blob: 91a1a2a162cf6627c08faef4ce6ddb2345ed8880 [file] [log] [blame]
Artem Titovb6c62012019-01-08 14:58:23 +01001/*
2 * Copyright (c) 2018 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 */
Artem Titovd57628f2019-03-22 12:34:25 +010010#ifndef API_TEST_PEERCONNECTION_QUALITY_TEST_FIXTURE_H_
11#define API_TEST_PEERCONNECTION_QUALITY_TEST_FIXTURE_H_
Artem Titovb6c62012019-01-08 14:58:23 +010012
Artem Titovf65a89b2019-05-07 11:56:44 +020013#include <map>
Artem Titovb6c62012019-01-08 14:58:23 +010014#include <memory>
15#include <string>
Artem Titov7581ff72019-05-15 15:45:33 +020016#include <utility>
Artem Titovb6c62012019-01-08 14:58:23 +010017#include <vector>
18
Artem Titova6a273d2019-02-07 16:43:51 +010019#include "absl/memory/memory.h"
Steve Anton10542f22019-01-11 09:11:00 -080020#include "api/async_resolver_factory.h"
21#include "api/call/call_factory_interface.h"
Artem Titovb6c62012019-01-08 14:58:23 +010022#include "api/fec_controller.h"
Artem Titov741daaf2019-03-21 14:37:36 +010023#include "api/function_view.h"
Artem Titovb6c62012019-01-08 14:58:23 +010024#include "api/media_transport_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080025#include "api/peer_connection_interface.h"
Danil Chapovalov9305d112019-09-04 13:16:09 +020026#include "api/rtc_event_log/rtc_event_log_factory_interface.h"
Danil Chapovalov1a5fc902019-06-10 12:58:03 +020027#include "api/task_queue/task_queue_factory.h"
Artem Titovd57628f2019-03-22 12:34:25 +010028#include "api/test/audio_quality_analyzer_interface.h"
Artem Titovb6c62012019-01-08 14:58:23 +010029#include "api/test/simulated_network.h"
Artem Titova8549212019-08-19 14:38:06 +020030#include "api/test/stats_observer_interface.h"
Artem Titovd57628f2019-03-22 12:34:25 +010031#include "api/test/video_quality_analyzer_interface.h"
Artem Titovb6c62012019-01-08 14:58:23 +010032#include "api/transport/network_control.h"
Artem Titovebd97702019-01-09 17:55:36 +010033#include "api/units/time_delta.h"
Artem Titovb6c62012019-01-08 14:58:23 +010034#include "api/video_codecs/video_decoder_factory.h"
35#include "api/video_codecs/video_encoder.h"
36#include "api/video_codecs/video_encoder_factory.h"
Artem Titovf65a89b2019-05-07 11:56:44 +020037#include "media/base/media_constants.h"
Artem Titovb6c62012019-01-08 14:58:23 +010038#include "rtc_base/network.h"
Steve Anton10542f22019-01-11 09:11:00 -080039#include "rtc_base/rtc_certificate_generator.h"
40#include "rtc_base/ssl_certificate.h"
Artem Titovb6c62012019-01-08 14:58:23 +010041#include "rtc_base/thread.h"
Artem Titovb6c62012019-01-08 14:58:23 +010042
43namespace webrtc {
Artem Titov0b443142019-03-20 11:11:08 +010044namespace webrtc_pc_e2e {
Artem Titovb6c62012019-01-08 14:58:23 +010045
Artem Titov7581ff72019-05-15 15:45:33 +020046constexpr size_t kDefaultSlidesWidth = 1850;
47constexpr size_t kDefaultSlidesHeight = 1110;
48
Artem Titovd57628f2019-03-22 12:34:25 +010049// API is in development. Can be changed/removed without notice.
Artem Titovb6c62012019-01-08 14:58:23 +010050class PeerConnectionE2EQualityTestFixture {
51 public:
Artem Titov7581ff72019-05-15 15:45:33 +020052 // Contains parameters for screen share scrolling.
53 //
54 // If scrolling is enabled, then it will be done by putting sliding window
55 // on source video and moving this window from top left corner to the
56 // bottom right corner of the picture.
57 //
58 // In such case source dimensions must be greater or equal to the sliding
59 // window dimensions. So |source_width| and |source_height| are the dimensions
60 // of the source frame, while |VideoConfig::width| and |VideoConfig::height|
61 // are the dimensions of the sliding window.
62 //
63 // Because |source_width| and |source_height| are dimensions of the source
64 // frame, they have to be width and height of videos from
65 // |ScreenShareConfig::slides_yuv_file_names|.
66 //
67 // Because scrolling have to be done on single slide it also requires, that
68 // |duration| must be less or equal to
69 // |ScreenShareConfig::slide_change_interval|.
70 struct ScrollingParams {
71 ScrollingParams(TimeDelta duration,
72 size_t source_width,
73 size_t source_height)
74 : duration(duration),
75 source_width(source_width),
76 source_height(source_height) {
77 RTC_CHECK_GT(duration.ms(), 0);
78 }
79
80 // Duration of scrolling.
81 TimeDelta duration;
82 // Width of source slides video.
83 size_t source_width;
84 // Height of source slides video.
85 size_t source_height;
86 };
87
Artem Titovebd97702019-01-09 17:55:36 +010088 // Contains screen share video stream properties.
Artem Titovb6c62012019-01-08 14:58:23 +010089 struct ScreenShareConfig {
Artem Titov7581ff72019-05-15 15:45:33 +020090 explicit ScreenShareConfig(TimeDelta slide_change_interval)
91 : slide_change_interval(slide_change_interval) {
92 RTC_CHECK_GT(slide_change_interval.ms(), 0);
93 }
94
Artem Titovebd97702019-01-09 17:55:36 +010095 // Shows how long one slide should be presented on the screen during
96 // slide generation.
97 TimeDelta slide_change_interval;
Artem Titov7581ff72019-05-15 15:45:33 +020098 // If true, slides will be generated programmatically. No scrolling params
99 // will be applied in such case.
100 bool generate_slides = false;
101 // If present scrolling will be applied. Please read extra requirement on
102 // |slides_yuv_file_names| for scrolling.
103 absl::optional<ScrollingParams> scrolling_params;
104 // Contains list of yuv files with slides.
105 //
106 // If empty, default set of slides will be used. In such case
107 // |VideoConfig::width| must be equal to |kDefaultSlidesWidth| and
108 // |VideoConfig::height| must be equal to |kDefaultSlidesHeight| or if
109 // |scrolling_params| are specified, then |ScrollingParams::source_width|
110 // must be equal to |kDefaultSlidesWidth| and
111 // |ScrollingParams::source_height| must be equal to |kDefaultSlidesHeight|.
Artem Titovb6c62012019-01-08 14:58:23 +0100112 std::vector<std::string> slides_yuv_file_names;
113 };
114
Artem Titova6a273d2019-02-07 16:43:51 +0100115 enum VideoGeneratorType { kDefault, kI420A, kI010 };
116
Artem Titovd70d80d2019-07-19 11:00:40 +0200117 // Config for Vp8 simulcast or Vp9 SVC testing.
118 //
119 // SVC support is limited:
120 // During SVC testing there is no SFU, so framework will try to emulate SFU
121 // behavior in regular p2p call. Because of it there are such limitations:
122 // * if |target_spatial_index| is not equal to the highest spatial layer
123 // then no packet/frame drops are allowed.
124 //
125 // If there will be any drops, that will affect requested layer, then
126 // WebRTC SVC implementation will continue decoding only the highest
127 // available layer and won't restore lower layers, so analyzer won't
128 // receive required data which will cause wrong results or test failures.
Artem Titovef3fd9c2019-06-13 16:36:52 +0200129 struct VideoSimulcastConfig {
130 VideoSimulcastConfig(int simulcast_streams_count, int target_spatial_index)
131 : simulcast_streams_count(simulcast_streams_count),
132 target_spatial_index(target_spatial_index) {
133 RTC_CHECK_GT(simulcast_streams_count, 1);
134 RTC_CHECK_GE(target_spatial_index, 0);
135 RTC_CHECK_LT(target_spatial_index, simulcast_streams_count);
136 }
137
138 // Specified amount of simulcast streams/SVC layers, depending on which
139 // encoder is used.
140 int simulcast_streams_count;
141 // Specifies spatial index of the video stream to analyze.
142 // There are 2 cases:
143 // 1. simulcast encoder is used:
144 // in such case |target_spatial_index| will specify the index of
145 // simulcast stream, that should be analyzed. Other streams will be
146 // dropped.
147 // 2. SVC encoder is used:
148 // in such case |target_spatial_index| will specify the top interesting
149 // spatial layer and all layers below, including target one will be
150 // processed. All layers above target one will be dropped.
151 int target_spatial_index;
152 };
153
Artem Titovebd97702019-01-09 17:55:36 +0100154 // Contains properties of single video stream.
Artem Titovb6c62012019-01-08 14:58:23 +0100155 struct VideoConfig {
Artem Titovc58c01d2019-02-28 13:19:12 +0100156 VideoConfig(size_t width, size_t height, int32_t fps)
157 : width(width), height(height), fps(fps) {}
158
Artem Titov7581ff72019-05-15 15:45:33 +0200159 // Video stream width.
Artem Titovc58c01d2019-02-28 13:19:12 +0100160 const size_t width;
Artem Titov7581ff72019-05-15 15:45:33 +0200161 // Video stream height.
Artem Titovc58c01d2019-02-28 13:19:12 +0100162 const size_t height;
163 const int32_t fps;
Artem Titovb6c62012019-01-08 14:58:23 +0100164 // Have to be unique among all specified configs for all peers in the call.
Artem Titov3481db22019-02-28 13:13:15 +0100165 // Will be auto generated if omitted.
Artem Titovb6c62012019-01-08 14:58:23 +0100166 absl::optional<std::string> stream_label;
Artem Titov9a7e7212019-02-28 16:34:17 +0100167 // Only 1 from |generator|, |input_file_name| and |screen_share_config| can
168 // be specified. If none of them are specified, then |generator| will be set
169 // to VideoGeneratorType::kDefault.
170 // If specified generator of this type will be used to produce input video.
Artem Titova6a273d2019-02-07 16:43:51 +0100171 absl::optional<VideoGeneratorType> generator;
172 // If specified this file will be used as input. Input video will be played
173 // in a circle.
Artem Titovb6c62012019-01-08 14:58:23 +0100174 absl::optional<std::string> input_file_name;
175 // If specified screen share video stream will be created as input.
176 absl::optional<ScreenShareConfig> screen_share_config;
Artem Titovef3fd9c2019-06-13 16:36:52 +0200177 // If presented video will be transfered in simulcast/SVC mode depending on
178 // which encoder is used.
179 //
Artem Titov46c7a162019-07-29 13:17:14 +0200180 // Simulcast is supported only from 1st added peer. For VP8 simulcast only
181 // without RTX is supported so it will be automatically disabled for all
182 // simulcast tracks. For VP9 simulcast enables VP9 SVC mode and support RTX,
183 // but only on non-lossy networks. See more in documentation to
184 // VideoSimulcastConfig.
Artem Titovef3fd9c2019-06-13 16:36:52 +0200185 absl::optional<VideoSimulcastConfig> simulcast_config;
Artem Titov1e49ab22019-07-30 13:17:25 +0200186 // Count of temporal layers for video stream. This value will be set into
187 // each RtpEncodingParameters of RtpParameters of corresponding
188 // RtpSenderInterface for this video stream.
189 absl::optional<int> temporal_layers_count;
Artem Titovb6c62012019-01-08 14:58:23 +0100190 // If specified the input stream will be also copied to specified file.
Artem Titova6a273d2019-02-07 16:43:51 +0100191 // It is actually one of the test's output file, which contains copy of what
192 // was captured during the test for this video stream on sender side.
193 // It is useful when generator is used as input.
Artem Titovb6c62012019-01-08 14:58:23 +0100194 absl::optional<std::string> input_dump_file_name;
195 // If specified this file will be used as output on the receiver side for
196 // this stream. If multiple streams will be produced by input stream,
Artem Titova6a273d2019-02-07 16:43:51 +0100197 // output files will be appended with indexes. The produced files contains
198 // what was rendered for this video stream on receiver side.
199 absl::optional<std::string> output_dump_file_name;
Artem Titovddef8d12019-09-06 14:31:50 +0200200 // If true will display input and output video on the user's screen.
201 bool show_on_screen = false;
Artem Titovb6c62012019-01-08 14:58:23 +0100202 };
203
Artem Titovebd97702019-01-09 17:55:36 +0100204 // Contains properties for audio in the call.
Artem Titovb6c62012019-01-08 14:58:23 +0100205 struct AudioConfig {
206 enum Mode {
207 kGenerated,
208 kFile,
209 };
Artem Titov3481db22019-02-28 13:13:15 +0100210 // Have to be unique among all specified configs for all peers in the call.
211 // Will be auto generated if omitted.
212 absl::optional<std::string> stream_label;
Artem Titov9a7e7212019-02-28 16:34:17 +0100213 Mode mode = kGenerated;
Artem Titovb6c62012019-01-08 14:58:23 +0100214 // Have to be specified only if mode = kFile
215 absl::optional<std::string> input_file_name;
216 // If specified the input stream will be also copied to specified file.
217 absl::optional<std::string> input_dump_file_name;
218 // If specified the output stream will be copied to specified file.
Artem Titova6a273d2019-02-07 16:43:51 +0100219 absl::optional<std::string> output_dump_file_name;
Artem Titovbc558ce2019-07-08 19:13:21 +0200220
Artem Titovb6c62012019-01-08 14:58:23 +0100221 // Audio options to use.
222 cricket::AudioOptions audio_options;
Artem Titovbc558ce2019-07-08 19:13:21 +0200223 // Sampling frequency of input audio data (from file or generated).
224 int sampling_frequency_in_hz = 48000;
Artem Titovb6c62012019-01-08 14:58:23 +0100225 };
226
Artem Titovd09bc552019-03-20 11:18:58 +0100227 // This class is used to fully configure one peer inside the call.
228 class PeerConfigurer {
229 public:
230 virtual ~PeerConfigurer() = default;
231
Danil Chapovalov1a5fc902019-06-10 12:58:03 +0200232 // The parameters of the following 8 methods will be passed to the
Artem Titovd09bc552019-03-20 11:18:58 +0100233 // PeerConnectionFactoryInterface implementation that will be created for
234 // this peer.
Danil Chapovalov1a5fc902019-06-10 12:58:03 +0200235 virtual PeerConfigurer* SetTaskQueueFactory(
236 std::unique_ptr<TaskQueueFactory> task_queue_factory) = 0;
Artem Titovd09bc552019-03-20 11:18:58 +0100237 virtual PeerConfigurer* SetCallFactory(
238 std::unique_ptr<CallFactoryInterface> call_factory) = 0;
239 virtual PeerConfigurer* SetEventLogFactory(
240 std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory) = 0;
241 virtual PeerConfigurer* SetFecControllerFactory(
242 std::unique_ptr<FecControllerFactoryInterface>
243 fec_controller_factory) = 0;
244 virtual PeerConfigurer* SetNetworkControllerFactory(
245 std::unique_ptr<NetworkControllerFactoryInterface>
246 network_controller_factory) = 0;
247 virtual PeerConfigurer* SetMediaTransportFactory(
248 std::unique_ptr<MediaTransportFactory> media_transport_factory) = 0;
249 virtual PeerConfigurer* SetVideoEncoderFactory(
250 std::unique_ptr<VideoEncoderFactory> video_encoder_factory) = 0;
251 virtual PeerConfigurer* SetVideoDecoderFactory(
252 std::unique_ptr<VideoDecoderFactory> video_decoder_factory) = 0;
253
254 // The parameters of the following 3 methods will be passed to the
255 // PeerConnectionInterface implementation that will be created for this
256 // peer.
257 virtual PeerConfigurer* SetAsyncResolverFactory(
258 std::unique_ptr<webrtc::AsyncResolverFactory>
259 async_resolver_factory) = 0;
260 virtual PeerConfigurer* SetRTCCertificateGenerator(
261 std::unique_ptr<rtc::RTCCertificateGeneratorInterface>
262 cert_generator) = 0;
263 virtual PeerConfigurer* SetSSLCertificateVerifier(
264 std::unique_ptr<rtc::SSLCertificateVerifier> tls_cert_verifier) = 0;
265
266 // Add new video stream to the call that will be sent from this peer.
267 virtual PeerConfigurer* AddVideoConfig(VideoConfig config) = 0;
268 // Set the audio stream for the call from this peer. If this method won't
269 // be invoked, this peer will send no audio.
270 virtual PeerConfigurer* SetAudioConfig(AudioConfig config) = 0;
271 // If is set, an RTCEventLog will be saved in that location and it will be
272 // available for further analysis.
273 virtual PeerConfigurer* SetRtcEventLogPath(std::string path) = 0;
Artem Titov70f80e52019-04-12 13:13:39 +0200274 // If is set, an AEC dump will be saved in that location and it will be
275 // available for further analysis.
276 virtual PeerConfigurer* SetAecDumpPath(std::string path) = 0;
Artem Titovd09bc552019-03-20 11:18:58 +0100277 virtual PeerConfigurer* SetRTCConfiguration(
278 PeerConnectionInterface::RTCConfiguration configuration) = 0;
Artem Titov85a9d912019-05-29 14:36:50 +0200279 // Set bitrate parameters on PeerConnection. This constraints will be
280 // applied to all summed RTP streams for this peer.
281 virtual PeerConfigurer* SetBitrateParameters(
282 PeerConnectionInterface::BitrateParameters bitrate_params) = 0;
Artem Titovd09bc552019-03-20 11:18:58 +0100283 };
284
Artem Titov728a0ee2019-08-20 13:36:35 +0200285 // Contains configuration for echo emulator.
286 struct EchoEmulationConfig {
287 // Delay which represents the echo path delay, i.e. how soon rendered signal
288 // should reach capturer.
289 TimeDelta echo_delay = TimeDelta::ms(50);
290 };
291
Artem Titova6a273d2019-02-07 16:43:51 +0100292 // Contains parameters, that describe how long framework should run quality
293 // test.
294 struct RunParams {
Artem Titovade945d2019-04-02 18:31:48 +0200295 explicit RunParams(TimeDelta run_duration) : run_duration(run_duration) {}
296
Artem Titova6a273d2019-02-07 16:43:51 +0100297 // Specifies how long the test should be run. This time shows how long
298 // the media should flow after connection was established and before
299 // it will be shut downed.
300 TimeDelta run_duration;
Artem Titovade945d2019-04-02 18:31:48 +0200301
Artem Titovf65a89b2019-05-07 11:56:44 +0200302 // Next two fields are used to specify concrete video codec, that should be
303 // used in the test. Video code will be negotiated in SDP during offer/
304 // answer exchange.
305 // Video codec name. You can find valid names in
306 // media/base/media_constants.h
307 std::string video_codec_name = cricket::kVp8CodecName;
308 // Map of parameters, that have to be specified on SDP codec. Each parameter
309 // is described by key and value. Codec parameters will match the specified
310 // map if and only if for each key from |video_codec_required_params| there
311 // will be a parameter with name equal to this key and parameter value will
312 // be equal to the value from |video_codec_required_params| for this key.
313 // If empty then only name will be used to match the codec.
314 std::map<std::string, std::string> video_codec_required_params;
315 bool use_ulp_fec = false;
316 bool use_flex_fec = false;
Artem Titovade945d2019-04-02 18:31:48 +0200317 // Specifies how much video encoder target bitrate should be different than
318 // target bitrate, provided by WebRTC stack. Must be greater then 0. Can be
319 // used to emulate overshooting of video encoders. This multiplier will
320 // be applied for all video encoder on both sides for all layers. Bitrate
321 // estimated by WebRTC stack will be multiplied on this multiplier and then
Erik Språng16cb8f52019-04-12 13:59:09 +0200322 // provided into VideoEncoder::SetRates(...).
Artem Titovade945d2019-04-02 18:31:48 +0200323 double video_encoder_bitrate_multiplier = 1.0;
Artem Titov39483c62019-07-19 17:03:52 +0200324 // If true will set conference mode in SDP media section for all video
325 // tracks for all peers.
326 bool use_conference_mode = false;
Artem Titov728a0ee2019-08-20 13:36:35 +0200327 // If specified echo emulation will be done, by mixing the render audio into
328 // the capture signal. In such case input signal will be reduced by half to
329 // avoid saturation or compression in the echo path simulation.
330 absl::optional<EchoEmulationConfig> echo_emulation_config;
Artem Titova6a273d2019-02-07 16:43:51 +0100331 };
332
Artem Titov18459222019-04-24 11:09:35 +0200333 // Represent an entity that will report quality metrics after test.
Artem Titova8549212019-08-19 14:38:06 +0200334 class QualityMetricsReporter : public StatsObserverInterface {
Artem Titov18459222019-04-24 11:09:35 +0200335 public:
336 virtual ~QualityMetricsReporter() = default;
337
338 // Invoked by framework after peer connection factory and peer connection
339 // itself will be created but before offer/answer exchange will be started.
340 virtual void Start(absl::string_view test_case_name) = 0;
341
342 // Invoked by framework after call is ended and peer connection factory and
343 // peer connection are destroyed.
344 virtual void StopAndReportResults() = 0;
345 };
346
Artem Titovd09bc552019-03-20 11:18:58 +0100347 virtual ~PeerConnectionE2EQualityTestFixture() = default;
348
Artem Titovba82e002019-03-15 15:57:53 +0100349 // Add activity that will be executed on the best effort at least after
350 // |target_time_since_start| after call will be set up (after offer/answer
351 // exchange, ICE gathering will be done and ICE candidates will passed to
352 // remote side). |func| param is amount of time spent from the call set up.
353 virtual void ExecuteAt(TimeDelta target_time_since_start,
354 std::function<void(TimeDelta)> func) = 0;
355 // Add activity that will be executed every |interval| with first execution
356 // on the best effort at least after |initial_delay_since_start| after call
357 // will be set up (after all participants will be connected). |func| param is
358 // amount of time spent from the call set up.
359 virtual void ExecuteEvery(TimeDelta initial_delay_since_start,
360 TimeDelta interval,
361 std::function<void(TimeDelta)> func) = 0;
362
Artem Titov18459222019-04-24 11:09:35 +0200363 // Add stats reporter entity to observe the test.
364 virtual void AddQualityMetricsReporter(
365 std::unique_ptr<QualityMetricsReporter> quality_metrics_reporter) = 0;
366
Artem Titovd09bc552019-03-20 11:18:58 +0100367 // Add a new peer to the call and return an object through which caller
368 // can configure peer's behavior.
369 // |network_thread| will be used as network thread for peer's peer connection
370 // |network_manager| will be used to provide network interfaces for peer's
371 // peer connection.
372 // |configurer| function will be used to configure peer in the call.
373 virtual void AddPeer(rtc::Thread* network_thread,
374 rtc::NetworkManager* network_manager,
375 rtc::FunctionView<void(PeerConfigurer*)> configurer) = 0;
376 virtual void Run(RunParams run_params) = 0;
Artem Titovb93c4e62019-05-02 10:52:07 +0200377
378 // Returns real test duration - the time of test execution measured during
379 // test. Client must call this method only after test is finished (after
380 // Run(...) method returned). Test execution time is time from end of call
381 // setup (offer/answer, ICE candidates exchange done and ICE connected) to
382 // start of call tear down (PeerConnection closed).
383 virtual TimeDelta GetRealTestDuration() const = 0;
Artem Titovb6c62012019-01-08 14:58:23 +0100384};
385
Artem Titov0b443142019-03-20 11:11:08 +0100386} // namespace webrtc_pc_e2e
Artem Titovb6c62012019-01-08 14:58:23 +0100387} // namespace webrtc
388
Artem Titovd57628f2019-03-22 12:34:25 +0100389#endif // API_TEST_PEERCONNECTION_QUALITY_TEST_FIXTURE_H_