| 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 <stdio.h> |
| 12 |
| 13 | #include <memory> |
| 14 | #include <string> |
| 15 | #include <vector> |
| 16 |
| 17 | #include "absl/flags/flag.h" |
| 18 | #include "absl/flags/parse.h" |
| 19 | #include "absl/types/optional.h" |
| 20 | #include "api/test/simulated_network.h" |
| 21 | #include "api/test/video_quality_test_fixture.h" |
| 22 | #include "api/transport/bitrate_settings.h" |
| 23 | #include "api/video_codecs/video_codec.h" |
| 24 | #include "rtc_base/checks.h" |
| 25 | #include "rtc_base/logging.h" |
| 26 | #include "rtc_base/string_encode.h" |
| 27 | #include "system_wrappers/include/field_trial.h" |
| 28 | #include "test/field_trial.h" |
| 29 | #include "test/gtest.h" |
| 30 | #include "test/run_test.h" |
| 31 | #include "test/test_flags.h" |
| 32 | #include "video/video_quality_test.h" |
| 33 |
| 34 | using ::webrtc::BitrateConstraints; |
| 35 | using ::webrtc::BuiltInNetworkBehaviorConfig; |
| 36 | using ::webrtc::InterLayerPredMode; |
| 37 | using ::webrtc::SdpVideoFormat; |
| 38 | using ::webrtc::VideoQualityTest; |
| 39 |
| 40 | // Flags common with video loopback, with different default values. |
| 41 | ABSL_FLAG(int, width, 1850, "Video width (crops source)."); |
| 42 | size_t Width() { |
| 43 | return static_cast<size_t>(absl::GetFlag(FLAGS_width)); |
| 44 | } |
| 45 |
| 46 | ABSL_FLAG(int, height, 1110, "Video height (crops source)."); |
| 47 | size_t Height() { |
| 48 | return static_cast<size_t>(absl::GetFlag(FLAGS_height)); |
| 49 | } |
| 50 |
| 51 | ABSL_FLAG(int, fps, 5, "Frames per second."); |
| 52 | int Fps() { |
| 53 | return absl::GetFlag(FLAGS_fps); |
| 54 | } |
| 55 |
| 56 | ABSL_FLAG(int, min_bitrate, 50, "Call and stream min bitrate in kbps."); |
| 57 | int MinBitrateKbps() { |
| 58 | return absl::GetFlag(FLAGS_min_bitrate); |
| 59 | } |
| 60 |
| 61 | ABSL_FLAG(int, start_bitrate, 300, "Call start bitrate in kbps."); |
| 62 | int StartBitrateKbps() { |
| 63 | return absl::GetFlag(FLAGS_start_bitrate); |
| 64 | } |
| 65 |
| 66 | ABSL_FLAG(int, target_bitrate, 200, "Stream target bitrate in kbps."); |
| 67 | int TargetBitrateKbps() { |
| 68 | return absl::GetFlag(FLAGS_target_bitrate); |
| 69 | } |
| 70 |
| 71 | ABSL_FLAG(int, max_bitrate, 1000, "Call and stream max bitrate in kbps."); |
| 72 | int MaxBitrateKbps() { |
| 73 | return absl::GetFlag(FLAGS_max_bitrate); |
| 74 | } |
| 75 |
| 76 | ABSL_FLAG(int, num_temporal_layers, 2, "Number of temporal layers to use."); |
| 77 | int NumTemporalLayers() { |
| 78 | return absl::GetFlag(FLAGS_num_temporal_layers); |
| 79 | } |
| 80 |
| 81 | // Flags common with video loopback, with equal default values. |
| 82 | ABSL_FLAG(std::string, codec, "VP8", "Video codec to use."); |
| 83 | std::string Codec() { |
| 84 | return absl::GetFlag(FLAGS_codec); |
| 85 | } |
| 86 |
| 87 | ABSL_FLAG(std::string, |
| 88 | rtc_event_log_name, |
| 89 | "", |
| 90 | "Filename for rtc event log. Two files " |
| 91 | "with \"_send\" and \"_recv\" suffixes will be created."); |
| 92 | std::string RtcEventLogName() { |
| 93 | return absl::GetFlag(FLAGS_rtc_event_log_name); |
| 94 | } |
| 95 |
| 96 | ABSL_FLAG(std::string, |
| 97 | rtp_dump_name, |
| 98 | "", |
| 99 | "Filename for dumped received RTP stream."); |
| 100 | std::string RtpDumpName() { |
| 101 | return absl::GetFlag(FLAGS_rtp_dump_name); |
| 102 | } |
| 103 |
| 104 | ABSL_FLAG(int, |
| 105 | selected_tl, |
| 106 | -1, |
| 107 | "Temporal layer to show or analyze. -1 to disable filtering."); |
| 108 | int SelectedTL() { |
| 109 | return absl::GetFlag(FLAGS_selected_tl); |
| 110 | } |
| 111 |
| 112 | ABSL_FLAG( |
| 113 | int, |
| 114 | duration, |
| 115 | 0, |
| 116 | "Duration of the test in seconds. If 0, rendered will be shown instead."); |
| 117 | int DurationSecs() { |
| 118 | return absl::GetFlag(FLAGS_duration); |
| 119 | } |
| 120 |
| 121 | ABSL_FLAG(std::string, output_filename, "", "Target graph data filename."); |
| 122 | std::string OutputFilename() { |
| 123 | return absl::GetFlag(FLAGS_output_filename); |
| 124 | } |
| 125 |
| 126 | ABSL_FLAG(std::string, |
| 127 | graph_title, |
| 128 | "", |
| 129 | "If empty, title will be generated automatically."); |
| 130 | std::string GraphTitle() { |
| 131 | return absl::GetFlag(FLAGS_graph_title); |
| 132 | } |
| 133 |
| 134 | ABSL_FLAG(int, loss_percent, 0, "Percentage of packets randomly lost."); |
| 135 | int LossPercent() { |
| 136 | return absl::GetFlag(FLAGS_loss_percent); |
| 137 | } |
| 138 |
| 139 | ABSL_FLAG(int, |
| 140 | link_capacity, |
| 141 | 0, |
| 142 | "Capacity (kbps) of the fake link. 0 means infinite."); |
| 143 | int LinkCapacityKbps() { |
| 144 | return absl::GetFlag(FLAGS_link_capacity); |
| 145 | } |
| 146 |
| 147 | ABSL_FLAG(int, queue_size, 0, "Size of the bottleneck link queue in packets."); |
| 148 | int QueueSize() { |
| 149 | return absl::GetFlag(FLAGS_queue_size); |
| 150 | } |
| 151 |
| 152 | ABSL_FLAG(int, |
| 153 | avg_propagation_delay_ms, |
| 154 | 0, |
| 155 | "Average link propagation delay in ms."); |
| 156 | int AvgPropagationDelayMs() { |
| 157 | return absl::GetFlag(FLAGS_avg_propagation_delay_ms); |
| 158 | } |
| 159 |
| 160 | ABSL_FLAG(int, |
| 161 | std_propagation_delay_ms, |
| 162 | 0, |
| 163 | "Link propagation delay standard deviation in ms."); |
| 164 | int StdPropagationDelayMs() { |
| 165 | return absl::GetFlag(FLAGS_std_propagation_delay_ms); |
| 166 | } |
| 167 |
| 168 | ABSL_FLAG(int, num_streams, 0, "Number of streams to show or analyze."); |
| 169 | int NumStreams() { |
| 170 | return absl::GetFlag(FLAGS_num_streams); |
| 171 | } |
| 172 |
| 173 | ABSL_FLAG(int, |
| 174 | selected_stream, |
| 175 | 0, |
| 176 | "ID of the stream to show or analyze. " |
| 177 | "Set to the number of streams to show them all."); |
| 178 | int SelectedStream() { |
| 179 | return absl::GetFlag(FLAGS_selected_stream); |
| 180 | } |
| 181 |
| 182 | ABSL_FLAG(int, num_spatial_layers, 1, "Number of spatial layers to use."); |
| 183 | int NumSpatialLayers() { |
| 184 | return absl::GetFlag(FLAGS_num_spatial_layers); |
| 185 | } |
| 186 |
| 187 | ABSL_FLAG(int, |
| 188 | inter_layer_pred, |
| 189 | 0, |
| 190 | "Inter-layer prediction mode. " |
| 191 | "0 - enabled, 1 - disabled, 2 - enabled only for key pictures."); |
| 192 | InterLayerPredMode InterLayerPred() { |
| 193 | if (absl::GetFlag(FLAGS_inter_layer_pred) == 0) { |
| 194 | return webrtc::InterLayerPredMode::kOn; |
| 195 | } else if (absl::GetFlag(FLAGS_inter_layer_pred) == 1) { |
| 196 | return webrtc::InterLayerPredMode::kOff; |
| 197 | } else { |
| 198 | RTC_DCHECK_EQ(absl::GetFlag(FLAGS_inter_layer_pred), 2); |
| 199 | return webrtc::InterLayerPredMode::kOnKeyPic; |
| 200 | } |
| 201 | } |
| 202 |
| 203 | ABSL_FLAG(int, |
| 204 | selected_sl, |
| 205 | -1, |
| 206 | "Spatial layer to show or analyze. -1 to disable filtering."); |
| 207 | int SelectedSL() { |
| 208 | return absl::GetFlag(FLAGS_selected_sl); |
| 209 | } |
| 210 |
| 211 | ABSL_FLAG(std::string, |
| 212 | stream0, |
| 213 | "", |
| 214 | "Comma separated values describing VideoStream for stream #0."); |
| 215 | std::string Stream0() { |
| 216 | return absl::GetFlag(FLAGS_stream0); |
| 217 | } |
| 218 |
| 219 | ABSL_FLAG(std::string, |
| 220 | stream1, |
| 221 | "", |
| 222 | "Comma separated values describing VideoStream for stream #1."); |
| 223 | std::string Stream1() { |
| 224 | return absl::GetFlag(FLAGS_stream1); |
| 225 | } |
| 226 |
| 227 | ABSL_FLAG(std::string, |
| 228 | sl0, |
| 229 | "", |
| 230 | "Comma separated values describing SpatialLayer for layer #0."); |
| 231 | std::string SL0() { |
| 232 | return absl::GetFlag(FLAGS_sl0); |
| 233 | } |
| 234 |
| 235 | ABSL_FLAG(std::string, |
| 236 | sl1, |
| 237 | "", |
| 238 | "Comma separated values describing SpatialLayer for layer #1."); |
| 239 | std::string SL1() { |
| 240 | return absl::GetFlag(FLAGS_sl1); |
| 241 | } |
| 242 |
| 243 | ABSL_FLAG(std::string, |
| 244 | encoded_frame_path, |
| 245 | "", |
| 246 | "The base path for encoded frame logs. Created files will have " |
| 247 | "the form <encoded_frame_path>.<n>.(recv|send.<m>).ivf"); |
| 248 | std::string EncodedFramePath() { |
| 249 | return absl::GetFlag(FLAGS_encoded_frame_path); |
| 250 | } |
| 251 |
| 252 | ABSL_FLAG(bool, logs, false, "print logs to stderr"); |
| 253 |
| 254 | ABSL_FLAG(bool, send_side_bwe, true, "Use send-side bandwidth estimation"); |
| 255 |
| 256 | ABSL_FLAG(bool, generic_descriptor, false, "Use the generic frame descriptor."); |
| 257 |
| 258 | ABSL_FLAG(bool, allow_reordering, false, "Allow packet reordering to occur"); |
| 259 |
| 260 | // Screenshare-specific flags. |
| 261 | ABSL_FLAG(int, |
| 262 | min_transmit_bitrate, |
| 263 | 400, |
| 264 | "Min transmit bitrate incl. padding."); |
| 265 | int MinTransmitBitrateKbps() { |
| 266 | return absl::GetFlag(FLAGS_min_transmit_bitrate); |
| 267 | } |
| 268 |
| 269 | ABSL_FLAG(bool, |
| 270 | generate_slides, |
| 271 | false, |
| 272 | "Whether to use randomly generated slides or read them from files."); |
| 273 | bool GenerateSlides() { |
| 274 | return absl::GetFlag(FLAGS_generate_slides); |
| 275 | } |
| 276 |
| 277 | ABSL_FLAG(int, |
| 278 | slide_change_interval, |
| 279 | 10, |
| 280 | "Interval (in seconds) between simulated slide changes."); |
| 281 | int SlideChangeInterval() { |
| 282 | return absl::GetFlag(FLAGS_slide_change_interval); |
| 283 | } |
| 284 |
| 285 | ABSL_FLAG( |
| 286 | int, |
| 287 | scroll_duration, |
| 288 | 0, |
| 289 | "Duration (in seconds) during which a slide will be scrolled into place."); |
| 290 | int ScrollDuration() { |
| 291 | return absl::GetFlag(FLAGS_scroll_duration); |
| 292 | } |
| 293 |
| 294 | ABSL_FLAG(std::string, |
| 295 | slides, |
| 296 | "", |
| 297 | "Comma-separated list of *.yuv files to display as slides."); |
| 298 | std::vector<std::string> Slides() { |
| 299 | std::vector<std::string> slides; |
| 300 | std::string slides_list = absl::GetFlag(FLAGS_slides); |
| 301 | rtc::tokenize(slides_list, ',', &slides); |
| 302 | return slides; |
| 303 | } |
| 304 |
| 305 | void Loopback() { |
| 306 | BuiltInNetworkBehaviorConfig pipe_config; |
| 307 | pipe_config.loss_percent = LossPercent(); |
| 308 | pipe_config.link_capacity_kbps = LinkCapacityKbps(); |
| 309 | pipe_config.queue_length_packets = QueueSize(); |
| 310 | pipe_config.queue_delay_ms = AvgPropagationDelayMs(); |
| 311 | pipe_config.delay_standard_deviation_ms = StdPropagationDelayMs(); |
| 312 | pipe_config.allow_reordering = absl::GetFlag(FLAGS_allow_reordering); |
| 313 |
| 314 | BitrateConstraints call_bitrate_config; |
| 315 | call_bitrate_config.min_bitrate_bps = MinBitrateKbps() * 1000; |
| 316 | call_bitrate_config.start_bitrate_bps = StartBitrateKbps() * 1000; |
| 317 | call_bitrate_config.max_bitrate_bps = -1; // Don't cap bandwidth estimate. |
| 318 |
| 319 | VideoQualityTest::Params params; |
| 320 | params.call.send_side_bwe = absl::GetFlag(FLAGS_send_side_bwe); |
| 321 | params.call.generic_descriptor = absl::GetFlag(FLAGS_generic_descriptor); |
| 322 | params.call.call_bitrate_config = call_bitrate_config; |
| 323 | params.video[0].enabled = true; |
| 324 | params.video[0].width = Width(); |
| 325 | params.video[0].height = Height(); |
| 326 | params.video[0].fps = Fps(); |
| 327 | params.video[0].min_bitrate_bps = MinBitrateKbps() * 1000; |
| 328 | params.video[0].target_bitrate_bps = TargetBitrateKbps() * 1000; |
| 329 | params.video[0].max_bitrate_bps = MaxBitrateKbps() * 1000; |
| 330 | params.video[0].codec = Codec(); |
| 331 | params.video[0].num_temporal_layers = NumTemporalLayers(); |
| 332 | params.video[0].selected_tl = SelectedTL(); |
| 333 | params.video[0].min_transmit_bps = MinTransmitBitrateKbps() * 1000; |
| 334 | params.screenshare[0].enabled = true; |
| 335 | params.screenshare[0].generate_slides = GenerateSlides(); |
| 336 | params.screenshare[0].slide_change_interval = SlideChangeInterval(); |
| 337 | params.screenshare[0].scroll_duration = ScrollDuration(); |
| 338 | params.screenshare[0].slides = Slides(); |
| 339 | params.config = pipe_config; |
| 340 | params.logging.rtc_event_log_name = RtcEventLogName(); |
| 341 | params.logging.rtp_dump_name = RtpDumpName(); |
| 342 | params.logging.encoded_frame_base_path = EncodedFramePath(); |
| 343 |
| 344 | if (NumStreams() > 1 && Stream0().empty() && Stream1().empty()) { |
| 345 | params.ss[0].infer_streams = true; |
| 346 | } |
| 347 |
| 348 | std::vector<std::string> stream_descriptors; |
| 349 | stream_descriptors.push_back(Stream0()); |
| 350 | stream_descriptors.push_back(Stream1()); |
| 351 | std::vector<std::string> SL_descriptors; |
| 352 | SL_descriptors.push_back(SL0()); |
| 353 | SL_descriptors.push_back(SL1()); |
| 354 | VideoQualityTest::FillScalabilitySettings( |
| 355 | ¶ms, 0, stream_descriptors, NumStreams(), SelectedStream(), |
| 356 | NumSpatialLayers(), SelectedSL(), InterLayerPred(), SL_descriptors); |
| 357 |
| 358 | auto fixture = std::make_unique<VideoQualityTest>(nullptr); |
| 359 | if (DurationSecs()) { |
| 360 | fixture->RunWithAnalyzer(params); |
| 361 | } else { |
| 362 | fixture->RunWithRenderers(params); |
| 363 | } |
| 364 | } |
| 365 |
| 366 | int main(int argc, char* argv[]) { |
| 367 | ::testing::InitGoogleTest(&argc, argv); |
| 368 | absl::ParseCommandLine(argc, argv); |
| 369 |
| 370 | rtc::LogMessage::SetLogToStderr(absl::GetFlag(FLAGS_logs)); |
| 371 |
| 372 | // InitFieldTrialsFromString stores the char*, so the char array must outlive |
| 373 | // the application. |
| 374 | const std::string field_trials = absl::GetFlag(FLAGS_force_fieldtrials); |
| 375 | webrtc::field_trial::InitFieldTrialsFromString(field_trials.c_str()); |
| 376 |
| 377 | webrtc::test::RunTest(Loopback); |
| 378 | return 0; |
| 379 | } |
| 380 |