blob: 76de3d0d6a8dd12b4a5d8d8af049ab7df09292ba [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>
16#include <vector>
17
Artem Titova6a273d2019-02-07 16:43:51 +010018#include "absl/memory/memory.h"
Steve Anton10542f22019-01-11 09:11:00 -080019#include "api/async_resolver_factory.h"
20#include "api/call/call_factory_interface.h"
Artem Titovb6c62012019-01-08 14:58:23 +010021#include "api/fec_controller.h"
Artem Titov741daaf2019-03-21 14:37:36 +010022#include "api/function_view.h"
Artem Titovb6c62012019-01-08 14:58:23 +010023#include "api/media_transport_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080024#include "api/peer_connection_interface.h"
Artem Titovd57628f2019-03-22 12:34:25 +010025#include "api/test/audio_quality_analyzer_interface.h"
Artem Titovb6c62012019-01-08 14:58:23 +010026#include "api/test/simulated_network.h"
Artem Titovd57628f2019-03-22 12:34:25 +010027#include "api/test/video_quality_analyzer_interface.h"
Artem Titovb6c62012019-01-08 14:58:23 +010028#include "api/transport/network_control.h"
Artem Titovebd97702019-01-09 17:55:36 +010029#include "api/units/time_delta.h"
Artem Titovb6c62012019-01-08 14:58:23 +010030#include "api/video_codecs/video_decoder_factory.h"
31#include "api/video_codecs/video_encoder.h"
32#include "api/video_codecs/video_encoder_factory.h"
33#include "logging/rtc_event_log/rtc_event_log_factory_interface.h"
Artem Titovf65a89b2019-05-07 11:56:44 +020034#include "media/base/media_constants.h"
Artem Titovb6c62012019-01-08 14:58:23 +010035#include "rtc_base/network.h"
Steve Anton10542f22019-01-11 09:11:00 -080036#include "rtc_base/rtc_certificate_generator.h"
37#include "rtc_base/ssl_certificate.h"
Artem Titovb6c62012019-01-08 14:58:23 +010038#include "rtc_base/thread.h"
Artem Titovb6c62012019-01-08 14:58:23 +010039
40namespace webrtc {
Artem Titov0b443142019-03-20 11:11:08 +010041namespace webrtc_pc_e2e {
Artem Titovb6c62012019-01-08 14:58:23 +010042
Artem Titovd57628f2019-03-22 12:34:25 +010043// API is in development. Can be changed/removed without notice.
Artem Titovb6c62012019-01-08 14:58:23 +010044class PeerConnectionE2EQualityTestFixture {
45 public:
Artem Titovebd97702019-01-09 17:55:36 +010046 // Contains screen share video stream properties.
Artem Titovb6c62012019-01-08 14:58:23 +010047 struct ScreenShareConfig {
48 // If true, slides will be generated programmatically.
49 bool generate_slides;
Artem Titovebd97702019-01-09 17:55:36 +010050 // Shows how long one slide should be presented on the screen during
51 // slide generation.
52 TimeDelta slide_change_interval;
Artem Titovb6c62012019-01-08 14:58:23 +010053 // If equal to 0, no scrolling will be applied.
Artem Titovebd97702019-01-09 17:55:36 +010054 TimeDelta scroll_duration;
Artem Titovb6c62012019-01-08 14:58:23 +010055 // If empty, default set of slides will be used.
56 std::vector<std::string> slides_yuv_file_names;
57 };
58
Artem Titova6a273d2019-02-07 16:43:51 +010059 enum VideoGeneratorType { kDefault, kI420A, kI010 };
60
Artem Titovebd97702019-01-09 17:55:36 +010061 // Contains properties of single video stream.
Artem Titovb6c62012019-01-08 14:58:23 +010062 struct VideoConfig {
Artem Titovc58c01d2019-02-28 13:19:12 +010063 VideoConfig(size_t width, size_t height, int32_t fps)
64 : width(width), height(height), fps(fps) {}
65
66 const size_t width;
67 const size_t height;
68 const int32_t fps;
Artem Titovb6c62012019-01-08 14:58:23 +010069 // Have to be unique among all specified configs for all peers in the call.
Artem Titov3481db22019-02-28 13:13:15 +010070 // Will be auto generated if omitted.
Artem Titovb6c62012019-01-08 14:58:23 +010071 absl::optional<std::string> stream_label;
Artem Titov9a7e7212019-02-28 16:34:17 +010072 // Only 1 from |generator|, |input_file_name| and |screen_share_config| can
73 // be specified. If none of them are specified, then |generator| will be set
74 // to VideoGeneratorType::kDefault.
75 // If specified generator of this type will be used to produce input video.
Artem Titova6a273d2019-02-07 16:43:51 +010076 absl::optional<VideoGeneratorType> generator;
77 // If specified this file will be used as input. Input video will be played
78 // in a circle.
Artem Titovb6c62012019-01-08 14:58:23 +010079 absl::optional<std::string> input_file_name;
80 // If specified screen share video stream will be created as input.
81 absl::optional<ScreenShareConfig> screen_share_config;
Artem Titov32232e92019-02-20 21:13:14 +010082 // Specifies spatial index of the video stream to analyze.
83 // There are 3 cases:
84 // 1. |target_spatial_index| omitted: in such case it will be assumed that
85 // video stream has not spatial layers and simulcast streams.
86 // 2. |target_spatial_index| presented and simulcast encoder is used:
87 // in such case |target_spatial_index| will specify the index of
Artem Titov3481db22019-02-28 13:13:15 +010088 // simulcast stream, that should be analyzed. Other streams will be
Artem Titov32232e92019-02-20 21:13:14 +010089 // dropped.
90 // 3. |target_spatial_index| presented and SVP encoder is used:
91 // in such case |target_spatial_index| will specify the top interesting
92 // spatial layer and all layers bellow, including target one will be
93 // processed. All layers above target one will be dropped.
94 absl::optional<int> target_spatial_index;
Artem Titovb6c62012019-01-08 14:58:23 +010095 // If specified the input stream will be also copied to specified file.
Artem Titova6a273d2019-02-07 16:43:51 +010096 // It is actually one of the test's output file, which contains copy of what
97 // was captured during the test for this video stream on sender side.
98 // It is useful when generator is used as input.
Artem Titovb6c62012019-01-08 14:58:23 +010099 absl::optional<std::string> input_dump_file_name;
100 // If specified this file will be used as output on the receiver side for
101 // this stream. If multiple streams will be produced by input stream,
Artem Titova6a273d2019-02-07 16:43:51 +0100102 // output files will be appended with indexes. The produced files contains
103 // what was rendered for this video stream on receiver side.
104 absl::optional<std::string> output_dump_file_name;
Artem Titovb6c62012019-01-08 14:58:23 +0100105 };
106
Artem Titovebd97702019-01-09 17:55:36 +0100107 // Contains properties for audio in the call.
Artem Titovb6c62012019-01-08 14:58:23 +0100108 struct AudioConfig {
109 enum Mode {
110 kGenerated,
111 kFile,
112 };
Artem Titov3481db22019-02-28 13:13:15 +0100113 // Have to be unique among all specified configs for all peers in the call.
114 // Will be auto generated if omitted.
115 absl::optional<std::string> stream_label;
Artem Titov9a7e7212019-02-28 16:34:17 +0100116 Mode mode = kGenerated;
Artem Titovb6c62012019-01-08 14:58:23 +0100117 // Have to be specified only if mode = kFile
118 absl::optional<std::string> input_file_name;
119 // If specified the input stream will be also copied to specified file.
120 absl::optional<std::string> input_dump_file_name;
121 // If specified the output stream will be copied to specified file.
Artem Titova6a273d2019-02-07 16:43:51 +0100122 absl::optional<std::string> output_dump_file_name;
Artem Titovb6c62012019-01-08 14:58:23 +0100123 // Audio options to use.
124 cricket::AudioOptions audio_options;
125 };
126
Artem Titovd09bc552019-03-20 11:18:58 +0100127 // This class is used to fully configure one peer inside the call.
128 class PeerConfigurer {
129 public:
130 virtual ~PeerConfigurer() = default;
131
132 // The parameters of the following 7 methods will be passed to the
133 // PeerConnectionFactoryInterface implementation that will be created for
134 // this peer.
135 virtual PeerConfigurer* SetCallFactory(
136 std::unique_ptr<CallFactoryInterface> call_factory) = 0;
137 virtual PeerConfigurer* SetEventLogFactory(
138 std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory) = 0;
139 virtual PeerConfigurer* SetFecControllerFactory(
140 std::unique_ptr<FecControllerFactoryInterface>
141 fec_controller_factory) = 0;
142 virtual PeerConfigurer* SetNetworkControllerFactory(
143 std::unique_ptr<NetworkControllerFactoryInterface>
144 network_controller_factory) = 0;
145 virtual PeerConfigurer* SetMediaTransportFactory(
146 std::unique_ptr<MediaTransportFactory> media_transport_factory) = 0;
147 virtual PeerConfigurer* SetVideoEncoderFactory(
148 std::unique_ptr<VideoEncoderFactory> video_encoder_factory) = 0;
149 virtual PeerConfigurer* SetVideoDecoderFactory(
150 std::unique_ptr<VideoDecoderFactory> video_decoder_factory) = 0;
151
152 // The parameters of the following 3 methods will be passed to the
153 // PeerConnectionInterface implementation that will be created for this
154 // peer.
155 virtual PeerConfigurer* SetAsyncResolverFactory(
156 std::unique_ptr<webrtc::AsyncResolverFactory>
157 async_resolver_factory) = 0;
158 virtual PeerConfigurer* SetRTCCertificateGenerator(
159 std::unique_ptr<rtc::RTCCertificateGeneratorInterface>
160 cert_generator) = 0;
161 virtual PeerConfigurer* SetSSLCertificateVerifier(
162 std::unique_ptr<rtc::SSLCertificateVerifier> tls_cert_verifier) = 0;
163
164 // Add new video stream to the call that will be sent from this peer.
165 virtual PeerConfigurer* AddVideoConfig(VideoConfig config) = 0;
166 // Set the audio stream for the call from this peer. If this method won't
167 // be invoked, this peer will send no audio.
168 virtual PeerConfigurer* SetAudioConfig(AudioConfig config) = 0;
169 // If is set, an RTCEventLog will be saved in that location and it will be
170 // available for further analysis.
171 virtual PeerConfigurer* SetRtcEventLogPath(std::string path) = 0;
Artem Titov70f80e52019-04-12 13:13:39 +0200172 // If is set, an AEC dump will be saved in that location and it will be
173 // available for further analysis.
174 virtual PeerConfigurer* SetAecDumpPath(std::string path) = 0;
Artem Titovd09bc552019-03-20 11:18:58 +0100175 virtual PeerConfigurer* SetRTCConfiguration(
176 PeerConnectionInterface::RTCConfiguration configuration) = 0;
177 };
178
Artem Titova6a273d2019-02-07 16:43:51 +0100179 // Contains parameters, that describe how long framework should run quality
180 // test.
181 struct RunParams {
Artem Titovade945d2019-04-02 18:31:48 +0200182 explicit RunParams(TimeDelta run_duration) : run_duration(run_duration) {}
183
Artem Titova6a273d2019-02-07 16:43:51 +0100184 // Specifies how long the test should be run. This time shows how long
185 // the media should flow after connection was established and before
186 // it will be shut downed.
187 TimeDelta run_duration;
Artem Titovade945d2019-04-02 18:31:48 +0200188
Artem Titovf65a89b2019-05-07 11:56:44 +0200189 // Next two fields are used to specify concrete video codec, that should be
190 // used in the test. Video code will be negotiated in SDP during offer/
191 // answer exchange.
192 // Video codec name. You can find valid names in
193 // media/base/media_constants.h
194 std::string video_codec_name = cricket::kVp8CodecName;
195 // Map of parameters, that have to be specified on SDP codec. Each parameter
196 // is described by key and value. Codec parameters will match the specified
197 // map if and only if for each key from |video_codec_required_params| there
198 // will be a parameter with name equal to this key and parameter value will
199 // be equal to the value from |video_codec_required_params| for this key.
200 // If empty then only name will be used to match the codec.
201 std::map<std::string, std::string> video_codec_required_params;
202 bool use_ulp_fec = false;
203 bool use_flex_fec = false;
Artem Titovade945d2019-04-02 18:31:48 +0200204 // Specifies how much video encoder target bitrate should be different than
205 // target bitrate, provided by WebRTC stack. Must be greater then 0. Can be
206 // used to emulate overshooting of video encoders. This multiplier will
207 // be applied for all video encoder on both sides for all layers. Bitrate
208 // estimated by WebRTC stack will be multiplied on this multiplier and then
Erik Språng16cb8f52019-04-12 13:59:09 +0200209 // provided into VideoEncoder::SetRates(...).
Artem Titovade945d2019-04-02 18:31:48 +0200210 double video_encoder_bitrate_multiplier = 1.0;
Artem Titova6a273d2019-02-07 16:43:51 +0100211 };
212
Artem Titov18459222019-04-24 11:09:35 +0200213 // Represent an entity that will report quality metrics after test.
214 class QualityMetricsReporter {
215 public:
216 virtual ~QualityMetricsReporter() = default;
217
218 // Invoked by framework after peer connection factory and peer connection
219 // itself will be created but before offer/answer exchange will be started.
220 virtual void Start(absl::string_view test_case_name) = 0;
221
222 // Invoked by framework after call is ended and peer connection factory and
223 // peer connection are destroyed.
224 virtual void StopAndReportResults() = 0;
225 };
226
Artem Titovd09bc552019-03-20 11:18:58 +0100227 virtual ~PeerConnectionE2EQualityTestFixture() = default;
228
Artem Titovba82e002019-03-15 15:57:53 +0100229 // Add activity that will be executed on the best effort at least after
230 // |target_time_since_start| after call will be set up (after offer/answer
231 // exchange, ICE gathering will be done and ICE candidates will passed to
232 // remote side). |func| param is amount of time spent from the call set up.
233 virtual void ExecuteAt(TimeDelta target_time_since_start,
234 std::function<void(TimeDelta)> func) = 0;
235 // Add activity that will be executed every |interval| with first execution
236 // on the best effort at least after |initial_delay_since_start| after call
237 // will be set up (after all participants will be connected). |func| param is
238 // amount of time spent from the call set up.
239 virtual void ExecuteEvery(TimeDelta initial_delay_since_start,
240 TimeDelta interval,
241 std::function<void(TimeDelta)> func) = 0;
242
Artem Titov18459222019-04-24 11:09:35 +0200243 // Add stats reporter entity to observe the test.
244 virtual void AddQualityMetricsReporter(
245 std::unique_ptr<QualityMetricsReporter> quality_metrics_reporter) = 0;
246
Artem Titovd09bc552019-03-20 11:18:58 +0100247 // Add a new peer to the call and return an object through which caller
248 // can configure peer's behavior.
249 // |network_thread| will be used as network thread for peer's peer connection
250 // |network_manager| will be used to provide network interfaces for peer's
251 // peer connection.
252 // |configurer| function will be used to configure peer in the call.
253 virtual void AddPeer(rtc::Thread* network_thread,
254 rtc::NetworkManager* network_manager,
255 rtc::FunctionView<void(PeerConfigurer*)> configurer) = 0;
256 virtual void Run(RunParams run_params) = 0;
Artem Titovb93c4e62019-05-02 10:52:07 +0200257
258 // Returns real test duration - the time of test execution measured during
259 // test. Client must call this method only after test is finished (after
260 // Run(...) method returned). Test execution time is time from end of call
261 // setup (offer/answer, ICE candidates exchange done and ICE connected) to
262 // start of call tear down (PeerConnection closed).
263 virtual TimeDelta GetRealTestDuration() const = 0;
Artem Titovb6c62012019-01-08 14:58:23 +0100264};
265
Artem Titov0b443142019-03-20 11:11:08 +0100266} // namespace webrtc_pc_e2e
Artem Titovb6c62012019-01-08 14:58:23 +0100267} // namespace webrtc
268
Artem Titovd57628f2019-03-22 12:34:25 +0100269#endif // API_TEST_PEERCONNECTION_QUALITY_TEST_FIXTURE_H_