Artem Titov | 0d51052 | 2022-04-19 13:01:03 +0200 | [diff] [blame] | 1 | /* |
| 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 Titov | bccb452 | 2022-06-01 22:32:15 +0200 | [diff] [blame] | 13 | #include <string> |
| 14 | |
Artem Titov | 0d51052 | 2022-04-19 13:01:03 +0200 | [diff] [blame] | 15 | #include "absl/types/optional.h" |
| 16 | #include "api/array_view.h" |
Artem Titov | 7017a13 | 2022-04-20 20:57:56 +0200 | [diff] [blame] | 17 | #include "rtc_base/checks.h" |
Artem Titov | bccb452 | 2022-06-01 22:32:15 +0200 | [diff] [blame] | 18 | #include "rtc_base/strings/string_builder.h" |
Artem Titov | 72bc2e2 | 2022-08-02 14:03:03 +0200 | [diff] [blame] | 19 | #include "test/testsupport/file_utils.h" |
Artem Titov | 0d51052 | 2022-04-19 13:01:03 +0200 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
| 22 | namespace webrtc_pc_e2e { |
Artem Titov | bccb452 | 2022-06-01 22:32:15 +0200 | [diff] [blame] | 23 | namespace { |
Artem Titov | 0d51052 | 2022-04-19 13:01:03 +0200 | [diff] [blame] | 24 | |
| 25 | using VideoCodecConfig = ::webrtc::webrtc_pc_e2e:: |
| 26 | PeerConnectionE2EQualityTestFixture::VideoCodecConfig; |
| 27 | using VideoSubscription = ::webrtc::webrtc_pc_e2e:: |
| 28 | PeerConnectionE2EQualityTestFixture::VideoSubscription; |
| 29 | |
Artem Titov | bccb452 | 2022-06-01 22:32:15 +0200 | [diff] [blame] | 30 | std::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 Titov | 7017a13 | 2022-04-20 20:57:56 +0200 | [diff] [blame] | 44 | PeerConnectionE2EQualityTestFixture::VideoResolution::VideoResolution( |
Artem Titov | 0d51052 | 2022-04-19 13:01:03 +0200 | [diff] [blame] | 45 | size_t width, |
| 46 | size_t height, |
| 47 | int32_t fps) |
| 48 | : width_(width), height_(height), fps_(fps), spec_(Spec::kNone) {} |
Artem Titov | 7017a13 | 2022-04-20 20:57:56 +0200 | [diff] [blame] | 49 | PeerConnectionE2EQualityTestFixture::VideoResolution::VideoResolution(Spec spec) |
Artem Titov | 0d51052 | 2022-04-19 13:01:03 +0200 | [diff] [blame] | 50 | : width_(0), height_(0), fps_(0), spec_(spec) {} |
| 51 | |
Artem Titov | 7017a13 | 2022-04-20 20:57:56 +0200 | [diff] [blame] | 52 | bool PeerConnectionE2EQualityTestFixture::VideoResolution::operator==( |
| 53 | const VideoResolution& other) const { |
Artem Titov | 0d51052 | 2022-04-19 13:01:03 +0200 | [diff] [blame] | 54 | 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 Titov | bccb452 | 2022-06-01 22:32:15 +0200 | [diff] [blame] | 63 | std::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 Titov | fd8ed05 | 2022-06-01 14:11:14 +0200 | [diff] [blame] | 71 | bool PeerConnectionE2EQualityTestFixture::VideoSubscription::operator==( |
| 72 | const VideoSubscription& other) const { |
| 73 | return default_resolution_ == other.default_resolution_ && |
| 74 | peers_resolution_ == other.peers_resolution_; |
| 75 | } |
| 76 | |
Artem Titov | 7017a13 | 2022-04-20 20:57:56 +0200 | [diff] [blame] | 77 | absl::optional<PeerConnectionE2EQualityTestFixture::VideoResolution> |
Artem Titov | 0d51052 | 2022-04-19 13:01:03 +0200 | [diff] [blame] | 78 | PeerConnectionE2EQualityTestFixture::VideoSubscription::GetMaxResolution( |
| 79 | rtc::ArrayView<const VideoConfig> video_configs) { |
Artem Titov | 7017a13 | 2022-04-20 20:57:56 +0200 | [diff] [blame] | 80 | std::vector<VideoResolution> resolutions; |
Artem Titov | 83962d9 | 2022-04-20 19:26:08 +0200 | [diff] [blame] | 81 | for (const auto& video_config : video_configs) { |
Artem Titov | 7017a13 | 2022-04-20 20:57:56 +0200 | [diff] [blame] | 82 | resolutions.push_back(video_config.GetResolution()); |
Artem Titov | 83962d9 | 2022-04-20 19:26:08 +0200 | [diff] [blame] | 83 | } |
| 84 | return GetMaxResolution(resolutions); |
| 85 | } |
| 86 | |
Artem Titov | 7017a13 | 2022-04-20 20:57:56 +0200 | [diff] [blame] | 87 | absl::optional<PeerConnectionE2EQualityTestFixture::VideoResolution> |
Artem Titov | 83962d9 | 2022-04-20 19:26:08 +0200 | [diff] [blame] | 88 | PeerConnectionE2EQualityTestFixture::VideoSubscription::GetMaxResolution( |
Artem Titov | 7017a13 | 2022-04-20 20:57:56 +0200 | [diff] [blame] | 89 | rtc::ArrayView<const VideoResolution> resolutions) { |
Artem Titov | 83962d9 | 2022-04-20 19:26:08 +0200 | [diff] [blame] | 90 | if (resolutions.empty()) { |
Artem Titov | 0d51052 | 2022-04-19 13:01:03 +0200 | [diff] [blame] | 91 | return absl::nullopt; |
| 92 | } |
| 93 | |
Artem Titov | 7017a13 | 2022-04-20 20:57:56 +0200 | [diff] [blame] | 94 | VideoResolution max_resolution; |
| 95 | for (const VideoResolution& resolution : resolutions) { |
Artem Titov | 83962d9 | 2022-04-20 19:26:08 +0200 | [diff] [blame] | 96 | if (max_resolution.width() < resolution.width()) { |
| 97 | max_resolution.set_width(resolution.width()); |
Artem Titov | 0d51052 | 2022-04-19 13:01:03 +0200 | [diff] [blame] | 98 | } |
Artem Titov | 83962d9 | 2022-04-20 19:26:08 +0200 | [diff] [blame] | 99 | if (max_resolution.height() < resolution.height()) { |
| 100 | max_resolution.set_height(resolution.height()); |
Artem Titov | 0d51052 | 2022-04-19 13:01:03 +0200 | [diff] [blame] | 101 | } |
Artem Titov | 83962d9 | 2022-04-20 19:26:08 +0200 | [diff] [blame] | 102 | if (max_resolution.fps() < resolution.fps()) { |
| 103 | max_resolution.set_fps(resolution.fps()); |
Artem Titov | 0d51052 | 2022-04-19 13:01:03 +0200 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | return max_resolution; |
| 107 | } |
| 108 | |
Artem Titov | 7c32192 | 2022-06-02 10:38:24 +0200 | [diff] [blame] | 109 | std::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 Titov | 72bc2e2 | 2022-08-02 14:03:03 +0200 | [diff] [blame] | 126 | PeerConnectionE2EQualityTestFixture::VideoDumpOptions::VideoDumpOptions( |
| 127 | absl::string_view output_directory, |
Artem Titov | d220925 | 2022-08-03 13:22:48 +0200 | [diff] [blame] | 128 | 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 Titov | 72bc2e2 | 2022-08-02 14:03:03 +0200 | [diff] [blame] | 133 | RTC_CHECK_GT(sampling_modulo, 0); |
| 134 | } |
Artem Titov | d220925 | 2022-08-03 13:22:48 +0200 | [diff] [blame] | 135 | PeerConnectionE2EQualityTestFixture::VideoDumpOptions::VideoDumpOptions( |
| 136 | absl::string_view output_directory, |
| 137 | bool export_frame_ids) |
| 138 | : VideoDumpOptions(output_directory, |
| 139 | kDefaultSamplingModulo, |
| 140 | export_frame_ids) {} |
Artem Titov | 72bc2e2 | 2022-08-02 14:03:03 +0200 | [diff] [blame] | 141 | |
| 142 | std::string |
| 143 | PeerConnectionE2EQualityTestFixture::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 Titov | d220925 | 2022-08-03 13:22:48 +0200 | [diff] [blame] | 150 | absl::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 Titov | 72bc2e2 | 2022-08-02 14:03:03 +0200 | [diff] [blame] | 159 | std::string |
| 160 | PeerConnectionE2EQualityTestFixture::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 Titov | d220925 | 2022-08-03 13:22:48 +0200 | [diff] [blame] | 168 | absl::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 Titov | 7017a13 | 2022-04-20 20:57:56 +0200 | [diff] [blame] | 178 | PeerConnectionE2EQualityTestFixture::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 Titov | 0d51052 | 2022-04-19 13:01:03 +0200 | [diff] [blame] | 186 | } // namespace webrtc_pc_e2e |
| 187 | } // namespace webrtc |