blob: 953819499096075f9ebb4045f4727715b25e6bf4 [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
13#include <memory>
14#include <string>
15#include <vector>
16
Artem Titova6a273d2019-02-07 16:43:51 +010017#include "absl/memory/memory.h"
Steve Anton10542f22019-01-11 09:11:00 -080018#include "api/async_resolver_factory.h"
19#include "api/call/call_factory_interface.h"
Artem Titovb6c62012019-01-08 14:58:23 +010020#include "api/fec_controller.h"
Artem Titov741daaf2019-03-21 14:37:36 +010021#include "api/function_view.h"
Artem Titovb6c62012019-01-08 14:58:23 +010022#include "api/media_transport_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080023#include "api/peer_connection_interface.h"
Artem Titovd57628f2019-03-22 12:34:25 +010024#include "api/test/audio_quality_analyzer_interface.h"
Artem Titovb6c62012019-01-08 14:58:23 +010025#include "api/test/simulated_network.h"
Artem Titovd57628f2019-03-22 12:34:25 +010026#include "api/test/video_quality_analyzer_interface.h"
Artem Titovb6c62012019-01-08 14:58:23 +010027#include "api/transport/network_control.h"
Artem Titovebd97702019-01-09 17:55:36 +010028#include "api/units/time_delta.h"
Artem Titovb6c62012019-01-08 14:58:23 +010029#include "api/video_codecs/video_decoder_factory.h"
30#include "api/video_codecs/video_encoder.h"
31#include "api/video_codecs/video_encoder_factory.h"
32#include "logging/rtc_event_log/rtc_event_log_factory_interface.h"
33#include "rtc_base/network.h"
Steve Anton10542f22019-01-11 09:11:00 -080034#include "rtc_base/rtc_certificate_generator.h"
35#include "rtc_base/ssl_certificate.h"
Artem Titovb6c62012019-01-08 14:58:23 +010036#include "rtc_base/thread.h"
Artem Titovb6c62012019-01-08 14:58:23 +010037
38namespace webrtc {
Artem Titov0b443142019-03-20 11:11:08 +010039namespace webrtc_pc_e2e {
Artem Titovb6c62012019-01-08 14:58:23 +010040
Artem Titovd57628f2019-03-22 12:34:25 +010041// API is in development. Can be changed/removed without notice.
Artem Titovb6c62012019-01-08 14:58:23 +010042class PeerConnectionE2EQualityTestFixture {
43 public:
Artem Titovebd97702019-01-09 17:55:36 +010044 // Contains screen share video stream properties.
Artem Titovb6c62012019-01-08 14:58:23 +010045 struct ScreenShareConfig {
46 // If true, slides will be generated programmatically.
47 bool generate_slides;
Artem Titovebd97702019-01-09 17:55:36 +010048 // Shows how long one slide should be presented on the screen during
49 // slide generation.
50 TimeDelta slide_change_interval;
Artem Titovb6c62012019-01-08 14:58:23 +010051 // If equal to 0, no scrolling will be applied.
Artem Titovebd97702019-01-09 17:55:36 +010052 TimeDelta scroll_duration;
Artem Titovb6c62012019-01-08 14:58:23 +010053 // If empty, default set of slides will be used.
54 std::vector<std::string> slides_yuv_file_names;
55 };
56
Artem Titova6a273d2019-02-07 16:43:51 +010057 enum VideoGeneratorType { kDefault, kI420A, kI010 };
58
Artem Titovebd97702019-01-09 17:55:36 +010059 // Contains properties of single video stream.
Artem Titovb6c62012019-01-08 14:58:23 +010060 struct VideoConfig {
Artem Titovc58c01d2019-02-28 13:19:12 +010061 VideoConfig(size_t width, size_t height, int32_t fps)
62 : width(width), height(height), fps(fps) {}
63
64 const size_t width;
65 const size_t height;
66 const int32_t fps;
Artem Titovb6c62012019-01-08 14:58:23 +010067 // Have to be unique among all specified configs for all peers in the call.
Artem Titov3481db22019-02-28 13:13:15 +010068 // Will be auto generated if omitted.
Artem Titovb6c62012019-01-08 14:58:23 +010069 absl::optional<std::string> stream_label;
Artem Titov9a7e7212019-02-28 16:34:17 +010070 // Only 1 from |generator|, |input_file_name| and |screen_share_config| can
71 // be specified. If none of them are specified, then |generator| will be set
72 // to VideoGeneratorType::kDefault.
73 // If specified generator of this type will be used to produce input video.
Artem Titova6a273d2019-02-07 16:43:51 +010074 absl::optional<VideoGeneratorType> generator;
75 // If specified this file will be used as input. Input video will be played
76 // in a circle.
Artem Titovb6c62012019-01-08 14:58:23 +010077 absl::optional<std::string> input_file_name;
78 // If specified screen share video stream will be created as input.
79 absl::optional<ScreenShareConfig> screen_share_config;
Artem Titov32232e92019-02-20 21:13:14 +010080 // Specifies spatial index of the video stream to analyze.
81 // There are 3 cases:
82 // 1. |target_spatial_index| omitted: in such case it will be assumed that
83 // video stream has not spatial layers and simulcast streams.
84 // 2. |target_spatial_index| presented and simulcast encoder is used:
85 // in such case |target_spatial_index| will specify the index of
Artem Titov3481db22019-02-28 13:13:15 +010086 // simulcast stream, that should be analyzed. Other streams will be
Artem Titov32232e92019-02-20 21:13:14 +010087 // dropped.
88 // 3. |target_spatial_index| presented and SVP encoder is used:
89 // in such case |target_spatial_index| will specify the top interesting
90 // spatial layer and all layers bellow, including target one will be
91 // processed. All layers above target one will be dropped.
92 absl::optional<int> target_spatial_index;
Artem Titovb6c62012019-01-08 14:58:23 +010093 // If specified the input stream will be also copied to specified file.
Artem Titova6a273d2019-02-07 16:43:51 +010094 // It is actually one of the test's output file, which contains copy of what
95 // was captured during the test for this video stream on sender side.
96 // It is useful when generator is used as input.
Artem Titovb6c62012019-01-08 14:58:23 +010097 absl::optional<std::string> input_dump_file_name;
98 // If specified this file will be used as output on the receiver side for
99 // this stream. If multiple streams will be produced by input stream,
Artem Titova6a273d2019-02-07 16:43:51 +0100100 // output files will be appended with indexes. The produced files contains
101 // what was rendered for this video stream on receiver side.
102 absl::optional<std::string> output_dump_file_name;
Artem Titovb6c62012019-01-08 14:58:23 +0100103 };
104
Artem Titovebd97702019-01-09 17:55:36 +0100105 // Contains properties for audio in the call.
Artem Titovb6c62012019-01-08 14:58:23 +0100106 struct AudioConfig {
107 enum Mode {
108 kGenerated,
109 kFile,
110 };
Artem Titov3481db22019-02-28 13:13:15 +0100111 // Have to be unique among all specified configs for all peers in the call.
112 // Will be auto generated if omitted.
113 absl::optional<std::string> stream_label;
Artem Titov9a7e7212019-02-28 16:34:17 +0100114 Mode mode = kGenerated;
Artem Titovb6c62012019-01-08 14:58:23 +0100115 // Have to be specified only if mode = kFile
116 absl::optional<std::string> input_file_name;
117 // If specified the input stream will be also copied to specified file.
118 absl::optional<std::string> input_dump_file_name;
119 // If specified the output stream will be copied to specified file.
Artem Titova6a273d2019-02-07 16:43:51 +0100120 absl::optional<std::string> output_dump_file_name;
Artem Titovb6c62012019-01-08 14:58:23 +0100121 // Audio options to use.
122 cricket::AudioOptions audio_options;
123 };
124
Artem Titovd09bc552019-03-20 11:18:58 +0100125 // This class is used to fully configure one peer inside the call.
126 class PeerConfigurer {
127 public:
128 virtual ~PeerConfigurer() = default;
129
130 // The parameters of the following 7 methods will be passed to the
131 // PeerConnectionFactoryInterface implementation that will be created for
132 // this peer.
133 virtual PeerConfigurer* SetCallFactory(
134 std::unique_ptr<CallFactoryInterface> call_factory) = 0;
135 virtual PeerConfigurer* SetEventLogFactory(
136 std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory) = 0;
137 virtual PeerConfigurer* SetFecControllerFactory(
138 std::unique_ptr<FecControllerFactoryInterface>
139 fec_controller_factory) = 0;
140 virtual PeerConfigurer* SetNetworkControllerFactory(
141 std::unique_ptr<NetworkControllerFactoryInterface>
142 network_controller_factory) = 0;
143 virtual PeerConfigurer* SetMediaTransportFactory(
144 std::unique_ptr<MediaTransportFactory> media_transport_factory) = 0;
145 virtual PeerConfigurer* SetVideoEncoderFactory(
146 std::unique_ptr<VideoEncoderFactory> video_encoder_factory) = 0;
147 virtual PeerConfigurer* SetVideoDecoderFactory(
148 std::unique_ptr<VideoDecoderFactory> video_decoder_factory) = 0;
149
150 // The parameters of the following 3 methods will be passed to the
151 // PeerConnectionInterface implementation that will be created for this
152 // peer.
153 virtual PeerConfigurer* SetAsyncResolverFactory(
154 std::unique_ptr<webrtc::AsyncResolverFactory>
155 async_resolver_factory) = 0;
156 virtual PeerConfigurer* SetRTCCertificateGenerator(
157 std::unique_ptr<rtc::RTCCertificateGeneratorInterface>
158 cert_generator) = 0;
159 virtual PeerConfigurer* SetSSLCertificateVerifier(
160 std::unique_ptr<rtc::SSLCertificateVerifier> tls_cert_verifier) = 0;
161
162 // Add new video stream to the call that will be sent from this peer.
163 virtual PeerConfigurer* AddVideoConfig(VideoConfig config) = 0;
164 // Set the audio stream for the call from this peer. If this method won't
165 // be invoked, this peer will send no audio.
166 virtual PeerConfigurer* SetAudioConfig(AudioConfig config) = 0;
167 // If is set, an RTCEventLog will be saved in that location and it will be
168 // available for further analysis.
169 virtual PeerConfigurer* SetRtcEventLogPath(std::string path) = 0;
Artem Titov70f80e52019-04-12 13:13:39 +0200170 // If is set, an AEC dump will be saved in that location and it will be
171 // available for further analysis.
172 virtual PeerConfigurer* SetAecDumpPath(std::string path) = 0;
Artem Titovd09bc552019-03-20 11:18:58 +0100173 virtual PeerConfigurer* SetRTCConfiguration(
174 PeerConnectionInterface::RTCConfiguration configuration) = 0;
175 };
176
Artem Titova6a273d2019-02-07 16:43:51 +0100177 // Contains parameters, that describe how long framework should run quality
178 // test.
179 struct RunParams {
Artem Titovade945d2019-04-02 18:31:48 +0200180 explicit RunParams(TimeDelta run_duration) : run_duration(run_duration) {}
181
Artem Titova6a273d2019-02-07 16:43:51 +0100182 // Specifies how long the test should be run. This time shows how long
183 // the media should flow after connection was established and before
184 // it will be shut downed.
185 TimeDelta run_duration;
Artem Titovade945d2019-04-02 18:31:48 +0200186
187 // Specifies how much video encoder target bitrate should be different than
188 // target bitrate, provided by WebRTC stack. Must be greater then 0. Can be
189 // used to emulate overshooting of video encoders. This multiplier will
190 // be applied for all video encoder on both sides for all layers. Bitrate
191 // estimated by WebRTC stack will be multiplied on this multiplier and then
Minyue Li7ddef1a2019-04-11 10:50:19 +0000192 // provided into VideoEncoder::SetRateAllocation(...).
Artem Titovade945d2019-04-02 18:31:48 +0200193 double video_encoder_bitrate_multiplier = 1.0;
Artem Titova6a273d2019-02-07 16:43:51 +0100194 };
195
Artem Titovd09bc552019-03-20 11:18:58 +0100196 virtual ~PeerConnectionE2EQualityTestFixture() = default;
197
Artem Titovba82e002019-03-15 15:57:53 +0100198 // Add activity that will be executed on the best effort at least after
199 // |target_time_since_start| after call will be set up (after offer/answer
200 // exchange, ICE gathering will be done and ICE candidates will passed to
201 // remote side). |func| param is amount of time spent from the call set up.
202 virtual void ExecuteAt(TimeDelta target_time_since_start,
203 std::function<void(TimeDelta)> func) = 0;
204 // Add activity that will be executed every |interval| with first execution
205 // on the best effort at least after |initial_delay_since_start| after call
206 // will be set up (after all participants will be connected). |func| param is
207 // amount of time spent from the call set up.
208 virtual void ExecuteEvery(TimeDelta initial_delay_since_start,
209 TimeDelta interval,
210 std::function<void(TimeDelta)> func) = 0;
211
Artem Titovd09bc552019-03-20 11:18:58 +0100212 // Add a new peer to the call and return an object through which caller
213 // can configure peer's behavior.
214 // |network_thread| will be used as network thread for peer's peer connection
215 // |network_manager| will be used to provide network interfaces for peer's
216 // peer connection.
217 // |configurer| function will be used to configure peer in the call.
218 virtual void AddPeer(rtc::Thread* network_thread,
219 rtc::NetworkManager* network_manager,
220 rtc::FunctionView<void(PeerConfigurer*)> configurer) = 0;
221 virtual void Run(RunParams run_params) = 0;
Artem Titovb6c62012019-01-08 14:58:23 +0100222};
223
Artem Titov0b443142019-03-20 11:11:08 +0100224} // namespace webrtc_pc_e2e
Artem Titovb6c62012019-01-08 14:58:23 +0100225} // namespace webrtc
226
Artem Titovd57628f2019-03-22 12:34:25 +0100227#endif // API_TEST_PEERCONNECTION_QUALITY_TEST_FIXTURE_H_