blob: 1fe07e0174ff2831a2d7edabc9e9724708b21306 [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 Chapovalov1a5fc902019-06-10 12:58:03 +020026#include "api/task_queue/task_queue_factory.h"
Artem Titovd57628f2019-03-22 12:34:25 +010027#include "api/test/audio_quality_analyzer_interface.h"
Artem Titovb6c62012019-01-08 14:58:23 +010028#include "api/test/simulated_network.h"
Artem Titovd57628f2019-03-22 12:34:25 +010029#include "api/test/video_quality_analyzer_interface.h"
Artem Titovb6c62012019-01-08 14:58:23 +010030#include "api/transport/network_control.h"
Artem Titovebd97702019-01-09 17:55:36 +010031#include "api/units/time_delta.h"
Artem Titovb6c62012019-01-08 14:58:23 +010032#include "api/video_codecs/video_decoder_factory.h"
33#include "api/video_codecs/video_encoder.h"
34#include "api/video_codecs/video_encoder_factory.h"
35#include "logging/rtc_event_log/rtc_event_log_factory_interface.h"
Artem Titovf65a89b2019-05-07 11:56:44 +020036#include "media/base/media_constants.h"
Artem Titovb6c62012019-01-08 14:58:23 +010037#include "rtc_base/network.h"
Steve Anton10542f22019-01-11 09:11:00 -080038#include "rtc_base/rtc_certificate_generator.h"
39#include "rtc_base/ssl_certificate.h"
Artem Titovb6c62012019-01-08 14:58:23 +010040#include "rtc_base/thread.h"
Artem Titovb6c62012019-01-08 14:58:23 +010041
42namespace webrtc {
Artem Titov0b443142019-03-20 11:11:08 +010043namespace webrtc_pc_e2e {
Artem Titovb6c62012019-01-08 14:58:23 +010044
Artem Titov7581ff72019-05-15 15:45:33 +020045constexpr size_t kDefaultSlidesWidth = 1850;
46constexpr size_t kDefaultSlidesHeight = 1110;
47
Artem Titovd57628f2019-03-22 12:34:25 +010048// API is in development. Can be changed/removed without notice.
Artem Titovb6c62012019-01-08 14:58:23 +010049class PeerConnectionE2EQualityTestFixture {
50 public:
Artem Titov7581ff72019-05-15 15:45:33 +020051 // Contains parameters for screen share scrolling.
52 //
53 // If scrolling is enabled, then it will be done by putting sliding window
54 // on source video and moving this window from top left corner to the
55 // bottom right corner of the picture.
56 //
57 // In such case source dimensions must be greater or equal to the sliding
58 // window dimensions. So |source_width| and |source_height| are the dimensions
59 // of the source frame, while |VideoConfig::width| and |VideoConfig::height|
60 // are the dimensions of the sliding window.
61 //
62 // Because |source_width| and |source_height| are dimensions of the source
63 // frame, they have to be width and height of videos from
64 // |ScreenShareConfig::slides_yuv_file_names|.
65 //
66 // Because scrolling have to be done on single slide it also requires, that
67 // |duration| must be less or equal to
68 // |ScreenShareConfig::slide_change_interval|.
69 struct ScrollingParams {
70 ScrollingParams(TimeDelta duration,
71 size_t source_width,
72 size_t source_height)
73 : duration(duration),
74 source_width(source_width),
75 source_height(source_height) {
76 RTC_CHECK_GT(duration.ms(), 0);
77 }
78
79 // Duration of scrolling.
80 TimeDelta duration;
81 // Width of source slides video.
82 size_t source_width;
83 // Height of source slides video.
84 size_t source_height;
85 };
86
Artem Titovebd97702019-01-09 17:55:36 +010087 // Contains screen share video stream properties.
Artem Titovb6c62012019-01-08 14:58:23 +010088 struct ScreenShareConfig {
Artem Titov7581ff72019-05-15 15:45:33 +020089 explicit ScreenShareConfig(TimeDelta slide_change_interval)
90 : slide_change_interval(slide_change_interval) {
91 RTC_CHECK_GT(slide_change_interval.ms(), 0);
92 }
93
Artem Titovebd97702019-01-09 17:55:36 +010094 // Shows how long one slide should be presented on the screen during
95 // slide generation.
96 TimeDelta slide_change_interval;
Artem Titov7581ff72019-05-15 15:45:33 +020097 // If true, slides will be generated programmatically. No scrolling params
98 // will be applied in such case.
99 bool generate_slides = false;
100 // If present scrolling will be applied. Please read extra requirement on
101 // |slides_yuv_file_names| for scrolling.
102 absl::optional<ScrollingParams> scrolling_params;
103 // Contains list of yuv files with slides.
104 //
105 // If empty, default set of slides will be used. In such case
106 // |VideoConfig::width| must be equal to |kDefaultSlidesWidth| and
107 // |VideoConfig::height| must be equal to |kDefaultSlidesHeight| or if
108 // |scrolling_params| are specified, then |ScrollingParams::source_width|
109 // must be equal to |kDefaultSlidesWidth| and
110 // |ScrollingParams::source_height| must be equal to |kDefaultSlidesHeight|.
Artem Titovb6c62012019-01-08 14:58:23 +0100111 std::vector<std::string> slides_yuv_file_names;
112 };
113
Artem Titova6a273d2019-02-07 16:43:51 +0100114 enum VideoGeneratorType { kDefault, kI420A, kI010 };
115
Artem Titovef3fd9c2019-06-13 16:36:52 +0200116 struct VideoSimulcastConfig {
117 VideoSimulcastConfig(int simulcast_streams_count, int target_spatial_index)
118 : simulcast_streams_count(simulcast_streams_count),
119 target_spatial_index(target_spatial_index) {
120 RTC_CHECK_GT(simulcast_streams_count, 1);
121 RTC_CHECK_GE(target_spatial_index, 0);
122 RTC_CHECK_LT(target_spatial_index, simulcast_streams_count);
123 }
124
125 // Specified amount of simulcast streams/SVC layers, depending on which
126 // encoder is used.
127 int simulcast_streams_count;
128 // Specifies spatial index of the video stream to analyze.
129 // There are 2 cases:
130 // 1. simulcast encoder is used:
131 // in such case |target_spatial_index| will specify the index of
132 // simulcast stream, that should be analyzed. Other streams will be
133 // dropped.
134 // 2. SVC encoder is used:
135 // in such case |target_spatial_index| will specify the top interesting
136 // spatial layer and all layers below, including target one will be
137 // processed. All layers above target one will be dropped.
138 int target_spatial_index;
Artem Titov594597c2019-07-18 13:39:41 +0200139 // If true will set conference mode in SDP media section for this track.
140 bool use_conference_mode = false;
Artem Titovef3fd9c2019-06-13 16:36:52 +0200141 };
142
Artem Titovebd97702019-01-09 17:55:36 +0100143 // Contains properties of single video stream.
Artem Titovb6c62012019-01-08 14:58:23 +0100144 struct VideoConfig {
Artem Titovc58c01d2019-02-28 13:19:12 +0100145 VideoConfig(size_t width, size_t height, int32_t fps)
146 : width(width), height(height), fps(fps) {}
147
Artem Titov7581ff72019-05-15 15:45:33 +0200148 // Video stream width.
Artem Titovc58c01d2019-02-28 13:19:12 +0100149 const size_t width;
Artem Titov7581ff72019-05-15 15:45:33 +0200150 // Video stream height.
Artem Titovc58c01d2019-02-28 13:19:12 +0100151 const size_t height;
152 const int32_t fps;
Artem Titovb6c62012019-01-08 14:58:23 +0100153 // Have to be unique among all specified configs for all peers in the call.
Artem Titov3481db22019-02-28 13:13:15 +0100154 // Will be auto generated if omitted.
Artem Titovb6c62012019-01-08 14:58:23 +0100155 absl::optional<std::string> stream_label;
Artem Titov9a7e7212019-02-28 16:34:17 +0100156 // Only 1 from |generator|, |input_file_name| and |screen_share_config| can
157 // be specified. If none of them are specified, then |generator| will be set
158 // to VideoGeneratorType::kDefault.
159 // If specified generator of this type will be used to produce input video.
Artem Titova6a273d2019-02-07 16:43:51 +0100160 absl::optional<VideoGeneratorType> generator;
161 // If specified this file will be used as input. Input video will be played
162 // in a circle.
Artem Titovb6c62012019-01-08 14:58:23 +0100163 absl::optional<std::string> input_file_name;
164 // If specified screen share video stream will be created as input.
165 absl::optional<ScreenShareConfig> screen_share_config;
Artem Titovef3fd9c2019-06-13 16:36:52 +0200166 // If presented video will be transfered in simulcast/SVC mode depending on
167 // which encoder is used.
168 //
169 // Simulcast is supported only from 1st added peer and for now only for
170 // Vp8 encoder. Also RTX doesn't supported with simulcast and will
171 // automatically disabled for tracks with simulcast.
172 absl::optional<VideoSimulcastConfig> simulcast_config;
Artem Titovb6c62012019-01-08 14:58:23 +0100173 // If specified the input stream will be also copied to specified file.
Artem Titova6a273d2019-02-07 16:43:51 +0100174 // It is actually one of the test's output file, which contains copy of what
175 // was captured during the test for this video stream on sender side.
176 // It is useful when generator is used as input.
Artem Titovb6c62012019-01-08 14:58:23 +0100177 absl::optional<std::string> input_dump_file_name;
178 // If specified this file will be used as output on the receiver side for
179 // this stream. If multiple streams will be produced by input stream,
Artem Titova6a273d2019-02-07 16:43:51 +0100180 // output files will be appended with indexes. The produced files contains
181 // what was rendered for this video stream on receiver side.
182 absl::optional<std::string> output_dump_file_name;
Artem Titovb6c62012019-01-08 14:58:23 +0100183 };
184
Artem Titovebd97702019-01-09 17:55:36 +0100185 // Contains properties for audio in the call.
Artem Titovb6c62012019-01-08 14:58:23 +0100186 struct AudioConfig {
187 enum Mode {
188 kGenerated,
189 kFile,
190 };
Artem Titov3481db22019-02-28 13:13:15 +0100191 // Have to be unique among all specified configs for all peers in the call.
192 // Will be auto generated if omitted.
193 absl::optional<std::string> stream_label;
Artem Titov9a7e7212019-02-28 16:34:17 +0100194 Mode mode = kGenerated;
Artem Titovb6c62012019-01-08 14:58:23 +0100195 // Have to be specified only if mode = kFile
196 absl::optional<std::string> input_file_name;
197 // If specified the input stream will be also copied to specified file.
198 absl::optional<std::string> input_dump_file_name;
199 // If specified the output stream will be copied to specified file.
Artem Titova6a273d2019-02-07 16:43:51 +0100200 absl::optional<std::string> output_dump_file_name;
Artem Titovbc558ce2019-07-08 19:13:21 +0200201
Artem Titovb6c62012019-01-08 14:58:23 +0100202 // Audio options to use.
203 cricket::AudioOptions audio_options;
Artem Titovbc558ce2019-07-08 19:13:21 +0200204 // Sampling frequency of input audio data (from file or generated).
205 int sampling_frequency_in_hz = 48000;
Artem Titovb6c62012019-01-08 14:58:23 +0100206 };
207
Artem Titovd09bc552019-03-20 11:18:58 +0100208 // This class is used to fully configure one peer inside the call.
209 class PeerConfigurer {
210 public:
211 virtual ~PeerConfigurer() = default;
212
Danil Chapovalov1a5fc902019-06-10 12:58:03 +0200213 // The parameters of the following 8 methods will be passed to the
Artem Titovd09bc552019-03-20 11:18:58 +0100214 // PeerConnectionFactoryInterface implementation that will be created for
215 // this peer.
Danil Chapovalov1a5fc902019-06-10 12:58:03 +0200216 virtual PeerConfigurer* SetTaskQueueFactory(
217 std::unique_ptr<TaskQueueFactory> task_queue_factory) = 0;
Artem Titovd09bc552019-03-20 11:18:58 +0100218 virtual PeerConfigurer* SetCallFactory(
219 std::unique_ptr<CallFactoryInterface> call_factory) = 0;
220 virtual PeerConfigurer* SetEventLogFactory(
221 std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory) = 0;
222 virtual PeerConfigurer* SetFecControllerFactory(
223 std::unique_ptr<FecControllerFactoryInterface>
224 fec_controller_factory) = 0;
225 virtual PeerConfigurer* SetNetworkControllerFactory(
226 std::unique_ptr<NetworkControllerFactoryInterface>
227 network_controller_factory) = 0;
228 virtual PeerConfigurer* SetMediaTransportFactory(
229 std::unique_ptr<MediaTransportFactory> media_transport_factory) = 0;
230 virtual PeerConfigurer* SetVideoEncoderFactory(
231 std::unique_ptr<VideoEncoderFactory> video_encoder_factory) = 0;
232 virtual PeerConfigurer* SetVideoDecoderFactory(
233 std::unique_ptr<VideoDecoderFactory> video_decoder_factory) = 0;
234
235 // The parameters of the following 3 methods will be passed to the
236 // PeerConnectionInterface implementation that will be created for this
237 // peer.
238 virtual PeerConfigurer* SetAsyncResolverFactory(
239 std::unique_ptr<webrtc::AsyncResolverFactory>
240 async_resolver_factory) = 0;
241 virtual PeerConfigurer* SetRTCCertificateGenerator(
242 std::unique_ptr<rtc::RTCCertificateGeneratorInterface>
243 cert_generator) = 0;
244 virtual PeerConfigurer* SetSSLCertificateVerifier(
245 std::unique_ptr<rtc::SSLCertificateVerifier> tls_cert_verifier) = 0;
246
247 // Add new video stream to the call that will be sent from this peer.
248 virtual PeerConfigurer* AddVideoConfig(VideoConfig config) = 0;
249 // Set the audio stream for the call from this peer. If this method won't
250 // be invoked, this peer will send no audio.
251 virtual PeerConfigurer* SetAudioConfig(AudioConfig config) = 0;
252 // If is set, an RTCEventLog will be saved in that location and it will be
253 // available for further analysis.
254 virtual PeerConfigurer* SetRtcEventLogPath(std::string path) = 0;
Artem Titov70f80e52019-04-12 13:13:39 +0200255 // If is set, an AEC dump will be saved in that location and it will be
256 // available for further analysis.
257 virtual PeerConfigurer* SetAecDumpPath(std::string path) = 0;
Artem Titovd09bc552019-03-20 11:18:58 +0100258 virtual PeerConfigurer* SetRTCConfiguration(
259 PeerConnectionInterface::RTCConfiguration configuration) = 0;
Artem Titov85a9d912019-05-29 14:36:50 +0200260 // Set bitrate parameters on PeerConnection. This constraints will be
261 // applied to all summed RTP streams for this peer.
262 virtual PeerConfigurer* SetBitrateParameters(
263 PeerConnectionInterface::BitrateParameters bitrate_params) = 0;
Artem Titovd09bc552019-03-20 11:18:58 +0100264 };
265
Artem Titova6a273d2019-02-07 16:43:51 +0100266 // Contains parameters, that describe how long framework should run quality
267 // test.
268 struct RunParams {
Artem Titovade945d2019-04-02 18:31:48 +0200269 explicit RunParams(TimeDelta run_duration) : run_duration(run_duration) {}
270
Artem Titova6a273d2019-02-07 16:43:51 +0100271 // Specifies how long the test should be run. This time shows how long
272 // the media should flow after connection was established and before
273 // it will be shut downed.
274 TimeDelta run_duration;
Artem Titovade945d2019-04-02 18:31:48 +0200275
Artem Titovf65a89b2019-05-07 11:56:44 +0200276 // Next two fields are used to specify concrete video codec, that should be
277 // used in the test. Video code will be negotiated in SDP during offer/
278 // answer exchange.
279 // Video codec name. You can find valid names in
280 // media/base/media_constants.h
281 std::string video_codec_name = cricket::kVp8CodecName;
282 // Map of parameters, that have to be specified on SDP codec. Each parameter
283 // is described by key and value. Codec parameters will match the specified
284 // map if and only if for each key from |video_codec_required_params| there
285 // will be a parameter with name equal to this key and parameter value will
286 // be equal to the value from |video_codec_required_params| for this key.
287 // If empty then only name will be used to match the codec.
288 std::map<std::string, std::string> video_codec_required_params;
289 bool use_ulp_fec = false;
290 bool use_flex_fec = false;
Artem Titovade945d2019-04-02 18:31:48 +0200291 // Specifies how much video encoder target bitrate should be different than
292 // target bitrate, provided by WebRTC stack. Must be greater then 0. Can be
293 // used to emulate overshooting of video encoders. This multiplier will
294 // be applied for all video encoder on both sides for all layers. Bitrate
295 // estimated by WebRTC stack will be multiplied on this multiplier and then
Erik Språng16cb8f52019-04-12 13:59:09 +0200296 // provided into VideoEncoder::SetRates(...).
Artem Titovade945d2019-04-02 18:31:48 +0200297 double video_encoder_bitrate_multiplier = 1.0;
Artem Titova6a273d2019-02-07 16:43:51 +0100298 };
299
Artem Titov18459222019-04-24 11:09:35 +0200300 // Represent an entity that will report quality metrics after test.
301 class QualityMetricsReporter {
302 public:
303 virtual ~QualityMetricsReporter() = default;
304
305 // Invoked by framework after peer connection factory and peer connection
306 // itself will be created but before offer/answer exchange will be started.
307 virtual void Start(absl::string_view test_case_name) = 0;
308
309 // Invoked by framework after call is ended and peer connection factory and
310 // peer connection are destroyed.
311 virtual void StopAndReportResults() = 0;
312 };
313
Artem Titovd09bc552019-03-20 11:18:58 +0100314 virtual ~PeerConnectionE2EQualityTestFixture() = default;
315
Artem Titovba82e002019-03-15 15:57:53 +0100316 // Add activity that will be executed on the best effort at least after
317 // |target_time_since_start| after call will be set up (after offer/answer
318 // exchange, ICE gathering will be done and ICE candidates will passed to
319 // remote side). |func| param is amount of time spent from the call set up.
320 virtual void ExecuteAt(TimeDelta target_time_since_start,
321 std::function<void(TimeDelta)> func) = 0;
322 // Add activity that will be executed every |interval| with first execution
323 // on the best effort at least after |initial_delay_since_start| after call
324 // will be set up (after all participants will be connected). |func| param is
325 // amount of time spent from the call set up.
326 virtual void ExecuteEvery(TimeDelta initial_delay_since_start,
327 TimeDelta interval,
328 std::function<void(TimeDelta)> func) = 0;
329
Artem Titov18459222019-04-24 11:09:35 +0200330 // Add stats reporter entity to observe the test.
331 virtual void AddQualityMetricsReporter(
332 std::unique_ptr<QualityMetricsReporter> quality_metrics_reporter) = 0;
333
Artem Titovd09bc552019-03-20 11:18:58 +0100334 // Add a new peer to the call and return an object through which caller
335 // can configure peer's behavior.
336 // |network_thread| will be used as network thread for peer's peer connection
337 // |network_manager| will be used to provide network interfaces for peer's
338 // peer connection.
339 // |configurer| function will be used to configure peer in the call.
340 virtual void AddPeer(rtc::Thread* network_thread,
341 rtc::NetworkManager* network_manager,
342 rtc::FunctionView<void(PeerConfigurer*)> configurer) = 0;
343 virtual void Run(RunParams run_params) = 0;
Artem Titovb93c4e62019-05-02 10:52:07 +0200344
345 // Returns real test duration - the time of test execution measured during
346 // test. Client must call this method only after test is finished (after
347 // Run(...) method returned). Test execution time is time from end of call
348 // setup (offer/answer, ICE candidates exchange done and ICE connected) to
349 // start of call tear down (PeerConnection closed).
350 virtual TimeDelta GetRealTestDuration() const = 0;
Artem Titovb6c62012019-01-08 14:58:23 +0100351};
352
Artem Titov0b443142019-03-20 11:11:08 +0100353} // namespace webrtc_pc_e2e
Artem Titovb6c62012019-01-08 14:58:23 +0100354} // namespace webrtc
355
Artem Titovd57628f2019-03-22 12:34:25 +0100356#endif // API_TEST_PEERCONNECTION_QUALITY_TEST_FIXTURE_H_