media_configuration.h (19560B)
1 /* 2 * Copyright (c) 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 #ifndef API_TEST_PCLF_MEDIA_CONFIGURATION_H_ 11 #define API_TEST_PCLF_MEDIA_CONFIGURATION_H_ 12 13 #include <stddef.h> 14 #include <stdint.h> 15 16 #include <functional> 17 #include <map> 18 #include <memory> 19 #include <optional> 20 #include <string> 21 #include <vector> 22 23 #include "absl/strings/string_view.h" 24 #include "api/array_view.h" 25 #include "api/audio_options.h" 26 #include "api/media_stream_interface.h" 27 #include "api/rtp_parameters.h" 28 #include "api/test/video/video_frame_writer.h" 29 #include "api/units/time_delta.h" 30 31 namespace webrtc { 32 namespace webrtc_pc_e2e { 33 34 constexpr size_t kDefaultSlidesWidth = 1850; 35 constexpr size_t kDefaultSlidesHeight = 1110; 36 37 // The index of required capturing device in OS provided list of video 38 // devices. On Linux and Windows the list will be obtained via 39 // webrtc::VideoCaptureModule::DeviceInfo, on Mac OS via 40 // [RTCCameraVideoCapturer captureDevices]. 41 enum class CapturingDeviceIndex : size_t {}; 42 43 // Contains parameters for screen share scrolling. 44 // 45 // If scrolling is enabled, then it will be done by putting sliding window 46 // on source video and moving this window from top left corner to the 47 // bottom right corner of the picture. 48 // 49 // In such case source dimensions must be greater or equal to the sliding 50 // window dimensions. So `source_width` and `source_height` are the dimensions 51 // of the source frame, while `VideoConfig::width` and `VideoConfig::height` 52 // are the dimensions of the sliding window. 53 // 54 // Because `source_width` and `source_height` are dimensions of the source 55 // frame, they have to be width and height of videos from 56 // `ScreenShareConfig::slides_yuv_file_names`. 57 // 58 // Because scrolling have to be done on single slide it also requires, that 59 // `duration` must be less or equal to 60 // `ScreenShareConfig::slide_change_interval`. 61 struct ScrollingParams { 62 // Duration of scrolling. 63 TimeDelta duration; 64 // Width of source slides video. 65 size_t source_width = kDefaultSlidesWidth; 66 // Height of source slides video. 67 size_t source_height = kDefaultSlidesHeight; 68 }; 69 70 // Contains screen share video stream properties. 71 struct ScreenShareConfig { 72 explicit ScreenShareConfig(TimeDelta slide_change_interval); 73 74 // Shows how long one slide should be presented on the screen during 75 // slide generation. 76 TimeDelta slide_change_interval; 77 // If true, slides will be generated programmatically. No scrolling params 78 // will be applied in such case. 79 bool generate_slides = false; 80 // If present scrolling will be applied. Please read extra requirement on 81 // `slides_yuv_file_names` for scrolling. 82 std::optional<ScrollingParams> scrolling_params; 83 // Contains list of yuv files with slides. 84 // 85 // If empty, default set of slides will be used. In such case 86 // `VideoConfig::width` must be equal to `kDefaultSlidesWidth` and 87 // `VideoConfig::height` must be equal to `kDefaultSlidesHeight` or if 88 // `scrolling_params` are specified, then `ScrollingParams::source_width` 89 // must be equal to `kDefaultSlidesWidth` and 90 // `ScrollingParams::source_height` must be equal to `kDefaultSlidesHeight`. 91 std::vector<std::string> slides_yuv_file_names; 92 }; 93 94 // Config for Vp8 simulcast or non-standard Vp9 SVC testing. 95 // 96 // To configure standard SVC setting, use `scalability_mode` in the 97 // `encoding_params` array. 98 // This configures Vp9 SVC by requesting simulcast layers, the request is 99 // internally converted to a request for SVC layers. 100 // 101 // SVC support is limited: 102 // During SVC testing there is no SFU, so framework will try to emulate SFU 103 // behavior in regular p2p call. Because of it there are such limitations: 104 // * if `target_spatial_index` is not equal to the highest spatial layer 105 // then no packet/frame drops are allowed. 106 // 107 // If there will be any drops, that will affect requested layer, then 108 // WebRTC SVC implementation will continue decoding only the highest 109 // available layer and won't restore lower layers, so analyzer won't 110 // receive required data which will cause wrong results or test failures. 111 struct VideoSimulcastConfig { 112 explicit VideoSimulcastConfig(int simulcast_streams_count); 113 114 // Specified amount of simulcast streams/SVC layers, depending on which 115 // encoder is used. 116 int simulcast_streams_count; 117 }; 118 119 // Configuration for the emulated Selective Forward Unit (SFU) 120 // 121 // The framework can optionally filter out frames that are decoded 122 // using an emulated SFU. 123 // When using simulcast or SVC, it's not always desirable to receive 124 // all frames. In a real world call, a SFU will only forward a subset 125 // of the frames. 126 // The emulated SFU is not able to change its configuration dynamically, 127 // if adaptation happens during the call, layers may be dropped and the 128 // analyzer won't receive the required data which will cause wrong results or 129 // test failures. 130 struct EmulatedSFUConfig { 131 EmulatedSFUConfig() = default; 132 explicit EmulatedSFUConfig(int target_layer_index); 133 EmulatedSFUConfig(std::optional<int> target_layer_index, 134 std::optional<int> target_temporal_index); 135 136 // Specifies simulcast or spatial index of the video stream to analyze. 137 // There are 2 cases: 138 // 1. simulcast encoding is used: 139 // in such case `target_layer_index` will specify the index of 140 // simulcast stream, that should be analyzed. Other streams will be 141 // dropped. 142 // 2. SVC encoding is used: 143 // in such case `target_layer_index` will specify the top interesting 144 // spatial layer and all layers below, including target one will be 145 // processed. All layers above target one will be dropped. 146 // If not specified then all streams will be received and analyzed. 147 // When set, it instructs the framework to create an emulated Selective 148 // Forwarding Unit (SFU) that will propagate only the requested layers. 149 std::optional<int> target_layer_index; 150 // Specifies the index of the maximum temporal unit to keep. 151 // If not specified then all temporal layers will be received and analyzed. 152 // When set, it instructs the framework to create an emulated Selective 153 // Forwarding Unit (SFU) that will propagate only up to the requested layer. 154 std::optional<int> target_temporal_index; 155 }; 156 157 class VideoResolution { 158 public: 159 // Determines special resolutions, which can't be expressed in terms of 160 // width, height and fps. 161 enum class Spec { 162 // No extra spec set. It describes a regular resolution described by 163 // width, height and fps. 164 kNone, 165 // Describes resolution which contains max value among all sender's 166 // video streams in each dimension (width, height, fps). 167 kMaxFromSender 168 }; 169 170 VideoResolution(size_t width, size_t height, int32_t fps); 171 explicit VideoResolution(Spec spec = Spec::kNone); 172 173 bool operator==(const VideoResolution& other) const; 174 bool operator!=(const VideoResolution& other) const; 175 176 size_t width() const { return width_; } 177 void set_width(size_t width) { width_ = width; } 178 size_t height() const { return height_; } 179 void set_height(size_t height) { height_ = height; } 180 int32_t fps() const { return fps_; } 181 void set_fps(int32_t fps) { fps_ = fps; } 182 183 // Returns if it is a regular resolution or not. The resolution is regular 184 // if it's spec is `Spec::kNone`. 185 bool IsRegular() const; 186 187 std::string ToString() const; 188 189 private: 190 size_t width_ = 0; 191 size_t height_ = 0; 192 int32_t fps_ = 0; 193 Spec spec_ = Spec::kNone; 194 }; 195 196 class VideoDumpOptions { 197 public: 198 static constexpr int kDefaultSamplingModulo = 1; 199 200 // output_directory - the output directory where stream will be dumped. The 201 // output files' names will be constructed as 202 // <stream_name>_<receiver_name>_<resolution>.<extension> for output dumps 203 // and <stream_name>_<resolution>.<extension> for input dumps. 204 // By default <extension> is "y4m". Resolution is in the format 205 // <width>x<height>_<fps>. 206 // sampling_modulo - the module for the video frames to be dumped. Modulo 207 // equals X means every Xth frame will be written to the dump file. The 208 // value must be greater than 0. (Default: 1) 209 // export_frame_ids - specifies if frame ids should be exported together 210 // with content of the stream. If true, an output file with the same name as 211 // video dump and suffix ".frame_ids.txt" will be created. It will contain 212 // the frame ids in the same order as original frames in the output 213 // file with stream content. File will contain one frame id per line. 214 // (Default: false) 215 // `video_frame_writer_factory` - factory function to create a video frame 216 // writer for input and output video files. (Default: Y4M video writer 217 // factory). 218 explicit VideoDumpOptions( 219 absl::string_view output_directory, 220 int sampling_modulo = kDefaultSamplingModulo, 221 bool export_frame_ids = false, 222 std::function<std::unique_ptr<test::VideoFrameWriter>( 223 absl::string_view file_name_prefix, 224 const VideoResolution& resolution)> video_frame_writer_factory = 225 Y4mVideoFrameWriterFactory); 226 VideoDumpOptions(absl::string_view output_directory, bool export_frame_ids); 227 228 VideoDumpOptions(const VideoDumpOptions&) = default; 229 VideoDumpOptions& operator=(const VideoDumpOptions&) = default; 230 VideoDumpOptions(VideoDumpOptions&&) = default; 231 VideoDumpOptions& operator=(VideoDumpOptions&&) = default; 232 233 std::string output_directory() const { return output_directory_; } 234 int sampling_modulo() const { return sampling_modulo_; } 235 bool export_frame_ids() const { return export_frame_ids_; } 236 237 std::unique_ptr<test::VideoFrameWriter> CreateInputDumpVideoFrameWriter( 238 absl::string_view stream_label, 239 const VideoResolution& resolution) const; 240 241 std::unique_ptr<test::VideoFrameWriter> CreateOutputDumpVideoFrameWriter( 242 absl::string_view stream_label, 243 absl::string_view receiver, 244 const VideoResolution& resolution) const; 245 246 std::string ToString() const; 247 248 private: 249 static std::unique_ptr<test::VideoFrameWriter> Y4mVideoFrameWriterFactory( 250 absl::string_view file_name_prefix, 251 const VideoResolution& resolution); 252 std::string GetInputDumpFileName(absl::string_view stream_label, 253 const VideoResolution& resolution) const; 254 // Returns file name for input frame ids dump if `export_frame_ids()` is 255 // true, std::nullopt otherwise. 256 std::optional<std::string> GetInputFrameIdsDumpFileName( 257 absl::string_view stream_label, 258 const VideoResolution& resolution) const; 259 std::string GetOutputDumpFileName(absl::string_view stream_label, 260 absl::string_view receiver, 261 const VideoResolution& resolution) const; 262 // Returns file name for output frame ids dump if `export_frame_ids()` is 263 // true, std::nullopt otherwise. 264 std::optional<std::string> GetOutputFrameIdsDumpFileName( 265 absl::string_view stream_label, 266 absl::string_view receiver, 267 const VideoResolution& resolution) const; 268 269 std::string output_directory_; 270 int sampling_modulo_ = 1; 271 bool export_frame_ids_ = false; 272 std::function<std::unique_ptr<test::VideoFrameWriter>( 273 absl::string_view file_name_prefix, 274 const VideoResolution& resolution)> 275 video_frame_writer_factory_; 276 }; 277 278 // Contains properties of single video stream. 279 struct VideoConfig { 280 explicit VideoConfig(const VideoResolution& resolution); 281 VideoConfig(size_t width, size_t height, int32_t fps); 282 VideoConfig(absl::string_view stream_label, 283 size_t width, 284 size_t height, 285 int32_t fps); 286 287 // Video stream width. 288 size_t width; 289 // Video stream height. 290 size_t height; 291 int32_t fps; 292 VideoResolution GetResolution() const { 293 return VideoResolution(width, height, fps); 294 } 295 296 // Have to be unique among all specified configs for all peers in the call. 297 // Will be auto generated if omitted. 298 std::optional<std::string> stream_label; 299 // Will be set for current video track. If equals to kText or kDetailed - 300 // screencast in on. 301 std::optional<VideoTrackInterface::ContentHint> content_hint; 302 // If presented video will be transfered in simulcast/SVC mode depending on 303 // which encoder is used. 304 // 305 // Simulcast is supported only from 1st added peer. For VP8 simulcast only 306 // without RTX is supported so it will be automatically disabled for all 307 // simulcast tracks. For VP9 simulcast enables VP9 SVC mode and support RTX, 308 // but only on non-lossy networks. See more in documentation to 309 // VideoSimulcastConfig. 310 std::optional<VideoSimulcastConfig> simulcast_config; 311 // Configuration for the emulated Selective Forward Unit (SFU). 312 std::optional<EmulatedSFUConfig> emulated_sfu_config; 313 // Encoding parameters for both singlecast and per simulcast layer. 314 // If singlecast is used, if not empty, a single value can be provided. 315 // If simulcast is used, if not empty, `encoding_params` size have to be 316 // equal to `simulcast_config.simulcast_streams_count`. Will be used to set 317 // transceiver send encoding params for each layer. 318 // RtpEncodingParameters::rid may be changed by fixture implementation to 319 // ensure signaling correctness. 320 std::vector<RtpEncodingParameters> encoding_params; 321 // Count of temporal layers for video stream. This value will be set into 322 // each RtpEncodingParameters of RtpParameters of corresponding 323 // RtpSenderInterface for this video stream. 324 std::optional<int> temporal_layers_count; 325 // If specified defines how input should be dumped. It is actually one of 326 // the test's output file, which contains copy of what was captured during 327 // the test for this video stream on sender side. It is useful when 328 // generator is used as input. 329 std::optional<VideoDumpOptions> input_dump_options; 330 // If specified defines how output should be dumped on the receiver side for 331 // this stream. The produced files contain what was rendered for this video 332 // stream on receiver side per each receiver. 333 std::optional<VideoDumpOptions> output_dump_options; 334 // If set to true uses fixed frame rate while dumping output video to the 335 // file. Requested `VideoSubscription::fps()` will be used as frame rate. 336 bool output_dump_use_fixed_framerate = false; 337 // If true will display input and output video on the user's screen. 338 bool show_on_screen = false; 339 // If specified, determines a sync group to which this video stream belongs. 340 // According to bugs.webrtc.org/4762 WebRTC supports synchronization only 341 // for pair of single audio and single video stream. 342 std::optional<std::string> sync_group; 343 // If specified, it will be set into RtpParameters of corresponding 344 // RtpSenderInterface for this video stream. 345 // Note that this setting takes precedence over `content_hint`. 346 std::optional<DegradationPreference> degradation_preference; 347 }; 348 349 // Contains properties for audio in the call. 350 struct AudioConfig { 351 // Have to be unique among all specified configs for all peers in the call. 352 // Will be auto generated if omitted. 353 std::optional<std::string> stream_label; 354 // If no file is specified an audio will be generated. 355 std::optional<std::string> input_file_name; 356 // If specified the input stream will be also copied to specified file. 357 std::optional<std::string> input_dump_file_name; 358 // If specified the output stream will be copied to specified file. 359 std::optional<std::string> output_dump_file_name; 360 361 // Audio options to use. 362 AudioOptions audio_options; 363 // Sampling frequency of input audio data (from file or generated). 364 int sampling_frequency_in_hz = 48000; 365 // If specified, determines a sync group to which this audio stream belongs. 366 // According to bugs.webrtc.org/4762 WebRTC supports synchronization only 367 // for pair of single audio and single video stream. 368 std::optional<std::string> sync_group; 369 }; 370 371 struct VideoCodecConfig { 372 explicit VideoCodecConfig(absl::string_view name); 373 VideoCodecConfig(absl::string_view name, 374 std::map<std::string, std::string> required_params); 375 // Next two fields are used to specify concrete video codec, that should be 376 // used in the test. Video code will be negotiated in SDP during offer/ 377 // answer exchange. 378 // Video codec name. You can find valid names in 379 // media/base/media_constants.h 380 std::string name; 381 // Map of parameters, that have to be specified on SDP codec. Each parameter 382 // is described by key and value. Codec parameters will match the specified 383 // map if and only if for each key from `required_params` there will be 384 // a parameter with name equal to this key and parameter value will be equal 385 // to the value from `required_params` for this key. 386 // If empty then only name will be used to match the codec. 387 std::map<std::string, std::string> required_params; 388 }; 389 390 // Subscription to the remote video streams. It declares which remote stream 391 // peer should receive and in which resolution (width x height x fps). 392 class VideoSubscription { 393 public: 394 // Returns the resolution constructed as maximum from all resolution 395 // dimensions: width, height and fps. 396 static std::optional<VideoResolution> GetMaxResolution( 397 ArrayView<const VideoConfig> video_configs); 398 static std::optional<VideoResolution> GetMaxResolution( 399 ArrayView<const VideoResolution> resolutions); 400 401 bool operator==(const VideoSubscription& other) const; 402 bool operator!=(const VideoSubscription& other) const; 403 404 // Subscribes receiver to all streams sent by the specified peer with 405 // specified resolution. It will override any resolution that was used in 406 // `SubscribeToAll` independently from methods call order. 407 VideoSubscription& SubscribeToPeer( 408 absl::string_view peer_name, 409 VideoResolution resolution = 410 VideoResolution(VideoResolution::Spec::kMaxFromSender)); 411 412 // Subscribes receiver to the all sent streams with specified resolution. 413 // If any stream was subscribed to with `SubscribeTo` method that will 414 // override resolution passed to this function independently from methods 415 // call order. 416 VideoSubscription& SubscribeToAllPeers( 417 VideoResolution resolution = 418 VideoResolution(VideoResolution::Spec::kMaxFromSender)); 419 420 // Returns resolution for specific sender. If no specific resolution was 421 // set for this sender, then will return resolution used for all streams. 422 // If subscription doesn't subscribe to all streams, `std::nullopt` will be 423 // returned. 424 std::optional<VideoResolution> GetResolutionForPeer( 425 absl::string_view peer_name) const; 426 427 // Returns a maybe empty list of senders for which peer explicitly 428 // subscribed to with specific resolution. 429 std::vector<std::string> GetSubscribedPeers() const; 430 431 std::string ToString() const; 432 433 private: 434 std::optional<VideoResolution> default_resolution_ = std::nullopt; 435 std::map<std::string, VideoResolution> peers_resolution_; 436 }; 437 438 // Contains configuration for echo emulator. 439 struct EchoEmulationConfig { 440 // Delay which represents the echo path delay, i.e. how soon rendered signal 441 // should reach capturer. 442 TimeDelta echo_delay = TimeDelta::Millis(50); 443 }; 444 445 } // namespace webrtc_pc_e2e 446 } // namespace webrtc 447 448 #endif // API_TEST_PCLF_MEDIA_CONFIGURATION_H_