peerconnection_quality_test_fixture.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. /*
  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. */
  10. #ifndef API_TEST_PEERCONNECTION_QUALITY_TEST_FIXTURE_H_
  11. #define API_TEST_PEERCONNECTION_QUALITY_TEST_FIXTURE_H_
  12. #include <map>
  13. #include <memory>
  14. #include <string>
  15. #include <utility>
  16. #include <vector>
  17. #include "absl/memory/memory.h"
  18. #include "absl/strings/string_view.h"
  19. #include "absl/types/optional.h"
  20. #include "api/async_resolver_factory.h"
  21. #include "api/call/call_factory_interface.h"
  22. #include "api/fec_controller.h"
  23. #include "api/function_view.h"
  24. #include "api/media_stream_interface.h"
  25. #include "api/peer_connection_interface.h"
  26. #include "api/rtc_event_log/rtc_event_log_factory_interface.h"
  27. #include "api/rtp_parameters.h"
  28. #include "api/task_queue/task_queue_factory.h"
  29. #include "api/test/audio_quality_analyzer_interface.h"
  30. #include "api/test/frame_generator_interface.h"
  31. #include "api/test/simulated_network.h"
  32. #include "api/test/stats_observer_interface.h"
  33. #include "api/test/track_id_stream_info_map.h"
  34. #include "api/test/video_quality_analyzer_interface.h"
  35. #include "api/transport/network_control.h"
  36. #include "api/units/time_delta.h"
  37. #include "api/video_codecs/video_decoder_factory.h"
  38. #include "api/video_codecs/video_encoder.h"
  39. #include "api/video_codecs/video_encoder_factory.h"
  40. #include "media/base/media_constants.h"
  41. #include "rtc_base/network.h"
  42. #include "rtc_base/rtc_certificate_generator.h"
  43. #include "rtc_base/ssl_certificate.h"
  44. #include "rtc_base/thread.h"
  45. namespace webrtc {
  46. namespace webrtc_pc_e2e {
  47. constexpr size_t kDefaultSlidesWidth = 1850;
  48. constexpr size_t kDefaultSlidesHeight = 1110;
  49. // API is in development. Can be changed/removed without notice.
  50. class PeerConnectionE2EQualityTestFixture {
  51. public:
  52. // The index of required capturing device in OS provided list of video
  53. // devices. On Linux and Windows the list will be obtained via
  54. // webrtc::VideoCaptureModule::DeviceInfo, on Mac OS via
  55. // [RTCCameraVideoCapturer captureDevices].
  56. enum class CapturingDeviceIndex : size_t {};
  57. // Contains parameters for screen share scrolling.
  58. //
  59. // If scrolling is enabled, then it will be done by putting sliding window
  60. // on source video and moving this window from top left corner to the
  61. // bottom right corner of the picture.
  62. //
  63. // In such case source dimensions must be greater or equal to the sliding
  64. // window dimensions. So |source_width| and |source_height| are the dimensions
  65. // of the source frame, while |VideoConfig::width| and |VideoConfig::height|
  66. // are the dimensions of the sliding window.
  67. //
  68. // Because |source_width| and |source_height| are dimensions of the source
  69. // frame, they have to be width and height of videos from
  70. // |ScreenShareConfig::slides_yuv_file_names|.
  71. //
  72. // Because scrolling have to be done on single slide it also requires, that
  73. // |duration| must be less or equal to
  74. // |ScreenShareConfig::slide_change_interval|.
  75. struct ScrollingParams {
  76. ScrollingParams(TimeDelta duration,
  77. size_t source_width,
  78. size_t source_height)
  79. : duration(duration),
  80. source_width(source_width),
  81. source_height(source_height) {
  82. RTC_CHECK_GT(duration.ms(), 0);
  83. }
  84. // Duration of scrolling.
  85. TimeDelta duration;
  86. // Width of source slides video.
  87. size_t source_width;
  88. // Height of source slides video.
  89. size_t source_height;
  90. };
  91. // Contains screen share video stream properties.
  92. struct ScreenShareConfig {
  93. explicit ScreenShareConfig(TimeDelta slide_change_interval)
  94. : slide_change_interval(slide_change_interval) {
  95. RTC_CHECK_GT(slide_change_interval.ms(), 0);
  96. }
  97. // Shows how long one slide should be presented on the screen during
  98. // slide generation.
  99. TimeDelta slide_change_interval;
  100. // If true, slides will be generated programmatically. No scrolling params
  101. // will be applied in such case.
  102. bool generate_slides = false;
  103. // If present scrolling will be applied. Please read extra requirement on
  104. // |slides_yuv_file_names| for scrolling.
  105. absl::optional<ScrollingParams> scrolling_params;
  106. // Contains list of yuv files with slides.
  107. //
  108. // If empty, default set of slides will be used. In such case
  109. // |VideoConfig::width| must be equal to |kDefaultSlidesWidth| and
  110. // |VideoConfig::height| must be equal to |kDefaultSlidesHeight| or if
  111. // |scrolling_params| are specified, then |ScrollingParams::source_width|
  112. // must be equal to |kDefaultSlidesWidth| and
  113. // |ScrollingParams::source_height| must be equal to |kDefaultSlidesHeight|.
  114. std::vector<std::string> slides_yuv_file_names;
  115. };
  116. // Config for Vp8 simulcast or Vp9 SVC testing.
  117. //
  118. // SVC support is limited:
  119. // During SVC testing there is no SFU, so framework will try to emulate SFU
  120. // behavior in regular p2p call. Because of it there are such limitations:
  121. // * if |target_spatial_index| is not equal to the highest spatial layer
  122. // then no packet/frame drops are allowed.
  123. //
  124. // If there will be any drops, that will affect requested layer, then
  125. // WebRTC SVC implementation will continue decoding only the highest
  126. // available layer and won't restore lower layers, so analyzer won't
  127. // receive required data which will cause wrong results or test failures.
  128. struct VideoSimulcastConfig {
  129. explicit VideoSimulcastConfig(int simulcast_streams_count)
  130. : simulcast_streams_count(simulcast_streams_count) {
  131. RTC_CHECK_GT(simulcast_streams_count, 1);
  132. }
  133. VideoSimulcastConfig(int simulcast_streams_count, int target_spatial_index)
  134. : simulcast_streams_count(simulcast_streams_count),
  135. target_spatial_index(target_spatial_index) {
  136. RTC_CHECK_GT(simulcast_streams_count, 1);
  137. RTC_CHECK_GE(target_spatial_index, 0);
  138. RTC_CHECK_LT(target_spatial_index, simulcast_streams_count);
  139. }
  140. // Specified amount of simulcast streams/SVC layers, depending on which
  141. // encoder is used.
  142. int simulcast_streams_count;
  143. // Specifies spatial index of the video stream to analyze.
  144. // There are 2 cases:
  145. // 1. simulcast encoder is used:
  146. // in such case |target_spatial_index| will specify the index of
  147. // simulcast stream, that should be analyzed. Other streams will be
  148. // dropped.
  149. // 2. SVC encoder is used:
  150. // in such case |target_spatial_index| will specify the top interesting
  151. // spatial layer and all layers below, including target one will be
  152. // processed. All layers above target one will be dropped.
  153. // If not specified than whatever stream will be received will be analyzed.
  154. // It requires Selective Forwarding Unit (SFU) to be configured in the
  155. // network.
  156. absl::optional<int> target_spatial_index;
  157. // Encoding parameters per simulcast layer. If not empty, |encoding_params|
  158. // size have to be equal to |simulcast_streams_count|. Will be used to set
  159. // transceiver send encoding params for simulcast layers. Applicable only
  160. // for codecs that support simulcast (ex. Vp8) and will be ignored
  161. // otherwise. RtpEncodingParameters::rid may be changed by fixture
  162. // implementation to ensure signaling correctness.
  163. std::vector<RtpEncodingParameters> encoding_params;
  164. };
  165. // Contains properties of single video stream.
  166. struct VideoConfig {
  167. VideoConfig(size_t width, size_t height, int32_t fps)
  168. : width(width), height(height), fps(fps) {}
  169. // Video stream width.
  170. const size_t width;
  171. // Video stream height.
  172. const size_t height;
  173. const int32_t fps;
  174. // Have to be unique among all specified configs for all peers in the call.
  175. // Will be auto generated if omitted.
  176. absl::optional<std::string> stream_label;
  177. // Will be set for current video track. If equals to kText or kDetailed -
  178. // screencast in on.
  179. absl::optional<VideoTrackInterface::ContentHint> content_hint;
  180. // If presented video will be transfered in simulcast/SVC mode depending on
  181. // which encoder is used.
  182. //
  183. // Simulcast is supported only from 1st added peer. For VP8 simulcast only
  184. // without RTX is supported so it will be automatically disabled for all
  185. // simulcast tracks. For VP9 simulcast enables VP9 SVC mode and support RTX,
  186. // but only on non-lossy networks. See more in documentation to
  187. // VideoSimulcastConfig.
  188. absl::optional<VideoSimulcastConfig> simulcast_config;
  189. // Count of temporal layers for video stream. This value will be set into
  190. // each RtpEncodingParameters of RtpParameters of corresponding
  191. // RtpSenderInterface for this video stream.
  192. absl::optional<int> temporal_layers_count;
  193. // Sets the maximum encode bitrate in bps. If this value is not set, the
  194. // encoder will be capped at an internal maximum value around 2 Mbps
  195. // depending on the resolution. This means that it will never be able to
  196. // utilize a high bandwidth link.
  197. absl::optional<int> max_encode_bitrate_bps;
  198. // Sets the minimum encode bitrate in bps. If this value is not set, the
  199. // encoder will use an internal minimum value. Please note that if this
  200. // value is set higher than the bandwidth of the link, the encoder will
  201. // generate more data than the link can handle regardless of the bandwidth
  202. // estimation.
  203. absl::optional<int> min_encode_bitrate_bps;
  204. // If specified the input stream will be also copied to specified file.
  205. // It is actually one of the test's output file, which contains copy of what
  206. // was captured during the test for this video stream on sender side.
  207. // It is useful when generator is used as input.
  208. absl::optional<std::string> input_dump_file_name;
  209. // If specified this file will be used as output on the receiver side for
  210. // this stream. If multiple streams will be produced by input stream,
  211. // output files will be appended with indexes. The produced files contains
  212. // what was rendered for this video stream on receiver side.
  213. absl::optional<std::string> output_dump_file_name;
  214. // If true will display input and output video on the user's screen.
  215. bool show_on_screen = false;
  216. // If specified, determines a sync group to which this video stream belongs.
  217. // According to bugs.webrtc.org/4762 WebRTC supports synchronization only
  218. // for pair of single audio and single video stream.
  219. absl::optional<std::string> sync_group;
  220. };
  221. // Contains properties for audio in the call.
  222. struct AudioConfig {
  223. enum Mode {
  224. kGenerated,
  225. kFile,
  226. };
  227. // Have to be unique among all specified configs for all peers in the call.
  228. // Will be auto generated if omitted.
  229. absl::optional<std::string> stream_label;
  230. Mode mode = kGenerated;
  231. // Have to be specified only if mode = kFile
  232. absl::optional<std::string> input_file_name;
  233. // If specified the input stream will be also copied to specified file.
  234. absl::optional<std::string> input_dump_file_name;
  235. // If specified the output stream will be copied to specified file.
  236. absl::optional<std::string> output_dump_file_name;
  237. // Audio options to use.
  238. cricket::AudioOptions audio_options;
  239. // Sampling frequency of input audio data (from file or generated).
  240. int sampling_frequency_in_hz = 48000;
  241. // If specified, determines a sync group to which this audio stream belongs.
  242. // According to bugs.webrtc.org/4762 WebRTC supports synchronization only
  243. // for pair of single audio and single video stream.
  244. absl::optional<std::string> sync_group;
  245. };
  246. // This class is used to fully configure one peer inside the call.
  247. class PeerConfigurer {
  248. public:
  249. virtual ~PeerConfigurer() = default;
  250. // Sets peer name that will be used to report metrics related to this peer.
  251. // If not set, some default name will be assigned. All names have to be
  252. // unique.
  253. virtual PeerConfigurer* SetName(absl::string_view name) = 0;
  254. // The parameters of the following 9 methods will be passed to the
  255. // PeerConnectionFactoryInterface implementation that will be created for
  256. // this peer.
  257. virtual PeerConfigurer* SetTaskQueueFactory(
  258. std::unique_ptr<TaskQueueFactory> task_queue_factory) = 0;
  259. virtual PeerConfigurer* SetCallFactory(
  260. std::unique_ptr<CallFactoryInterface> call_factory) = 0;
  261. virtual PeerConfigurer* SetEventLogFactory(
  262. std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory) = 0;
  263. virtual PeerConfigurer* SetFecControllerFactory(
  264. std::unique_ptr<FecControllerFactoryInterface>
  265. fec_controller_factory) = 0;
  266. virtual PeerConfigurer* SetNetworkControllerFactory(
  267. std::unique_ptr<NetworkControllerFactoryInterface>
  268. network_controller_factory) = 0;
  269. virtual PeerConfigurer* SetVideoEncoderFactory(
  270. std::unique_ptr<VideoEncoderFactory> video_encoder_factory) = 0;
  271. virtual PeerConfigurer* SetVideoDecoderFactory(
  272. std::unique_ptr<VideoDecoderFactory> video_decoder_factory) = 0;
  273. // Set a custom NetEqFactory to be used in the call.
  274. virtual PeerConfigurer* SetNetEqFactory(
  275. std::unique_ptr<NetEqFactory> neteq_factory) = 0;
  276. // The parameters of the following 4 methods will be passed to the
  277. // PeerConnectionInterface implementation that will be created for this
  278. // peer.
  279. virtual PeerConfigurer* SetAsyncResolverFactory(
  280. std::unique_ptr<webrtc::AsyncResolverFactory>
  281. async_resolver_factory) = 0;
  282. virtual PeerConfigurer* SetRTCCertificateGenerator(
  283. std::unique_ptr<rtc::RTCCertificateGeneratorInterface>
  284. cert_generator) = 0;
  285. virtual PeerConfigurer* SetSSLCertificateVerifier(
  286. std::unique_ptr<rtc::SSLCertificateVerifier> tls_cert_verifier) = 0;
  287. virtual PeerConfigurer* SetIceTransportFactory(
  288. std::unique_ptr<IceTransportFactory> factory) = 0;
  289. // Add new video stream to the call that will be sent from this peer.
  290. // Default implementation of video frames generator will be used.
  291. virtual PeerConfigurer* AddVideoConfig(VideoConfig config) = 0;
  292. // Add new video stream to the call that will be sent from this peer with
  293. // provided own implementation of video frames generator.
  294. virtual PeerConfigurer* AddVideoConfig(
  295. VideoConfig config,
  296. std::unique_ptr<test::FrameGeneratorInterface> generator) = 0;
  297. // Add new video stream to the call that will be sent from this peer.
  298. // Capturing device with specified index will be used to get input video.
  299. virtual PeerConfigurer* AddVideoConfig(
  300. VideoConfig config,
  301. CapturingDeviceIndex capturing_device_index) = 0;
  302. // Set the audio stream for the call from this peer. If this method won't
  303. // be invoked, this peer will send no audio.
  304. virtual PeerConfigurer* SetAudioConfig(AudioConfig config) = 0;
  305. // If is set, an RTCEventLog will be saved in that location and it will be
  306. // available for further analysis.
  307. virtual PeerConfigurer* SetRtcEventLogPath(std::string path) = 0;
  308. // If is set, an AEC dump will be saved in that location and it will be
  309. // available for further analysis.
  310. virtual PeerConfigurer* SetAecDumpPath(std::string path) = 0;
  311. virtual PeerConfigurer* SetRTCConfiguration(
  312. PeerConnectionInterface::RTCConfiguration configuration) = 0;
  313. // Set bitrate parameters on PeerConnection. This constraints will be
  314. // applied to all summed RTP streams for this peer.
  315. virtual PeerConfigurer* SetBitrateSettings(
  316. BitrateSettings bitrate_settings) = 0;
  317. };
  318. // Contains configuration for echo emulator.
  319. struct EchoEmulationConfig {
  320. // Delay which represents the echo path delay, i.e. how soon rendered signal
  321. // should reach capturer.
  322. TimeDelta echo_delay = TimeDelta::Millis(50);
  323. };
  324. struct VideoCodecConfig {
  325. explicit VideoCodecConfig(std::string name)
  326. : name(std::move(name)), required_params() {}
  327. VideoCodecConfig(std::string name,
  328. std::map<std::string, std::string> required_params)
  329. : name(std::move(name)), required_params(std::move(required_params)) {}
  330. // Next two fields are used to specify concrete video codec, that should be
  331. // used in the test. Video code will be negotiated in SDP during offer/
  332. // answer exchange.
  333. // Video codec name. You can find valid names in
  334. // media/base/media_constants.h
  335. std::string name = cricket::kVp8CodecName;
  336. // Map of parameters, that have to be specified on SDP codec. Each parameter
  337. // is described by key and value. Codec parameters will match the specified
  338. // map if and only if for each key from |required_params| there will be
  339. // a parameter with name equal to this key and parameter value will be equal
  340. // to the value from |required_params| for this key.
  341. // If empty then only name will be used to match the codec.
  342. std::map<std::string, std::string> required_params;
  343. };
  344. // Contains parameters, that describe how long framework should run quality
  345. // test.
  346. struct RunParams {
  347. explicit RunParams(TimeDelta run_duration) : run_duration(run_duration) {}
  348. // Specifies how long the test should be run. This time shows how long
  349. // the media should flow after connection was established and before
  350. // it will be shut downed.
  351. TimeDelta run_duration;
  352. // List of video codecs to use during the test. These codecs will be
  353. // negotiated in SDP during offer/answer exchange. The order of these codecs
  354. // during negotiation will be the same as in |video_codecs|. Codecs have
  355. // to be available in codecs list provided by peer connection to be
  356. // negotiated. If some of specified codecs won't be found, the test will
  357. // crash.
  358. // If list is empty Vp8 with no required_params will be used.
  359. std::vector<VideoCodecConfig> video_codecs;
  360. bool use_ulp_fec = false;
  361. bool use_flex_fec = false;
  362. // Specifies how much video encoder target bitrate should be different than
  363. // target bitrate, provided by WebRTC stack. Must be greater then 0. Can be
  364. // used to emulate overshooting of video encoders. This multiplier will
  365. // be applied for all video encoder on both sides for all layers. Bitrate
  366. // estimated by WebRTC stack will be multiplied on this multiplier and then
  367. // provided into VideoEncoder::SetRates(...).
  368. double video_encoder_bitrate_multiplier = 1.0;
  369. // If true will set conference mode in SDP media section for all video
  370. // tracks for all peers.
  371. bool use_conference_mode = false;
  372. // If specified echo emulation will be done, by mixing the render audio into
  373. // the capture signal. In such case input signal will be reduced by half to
  374. // avoid saturation or compression in the echo path simulation.
  375. absl::optional<EchoEmulationConfig> echo_emulation_config;
  376. };
  377. // Represent an entity that will report quality metrics after test.
  378. class QualityMetricsReporter : public StatsObserverInterface {
  379. public:
  380. virtual ~QualityMetricsReporter() = default;
  381. // Invoked by framework after peer connection factory and peer connection
  382. // itself will be created but before offer/answer exchange will be started.
  383. // |test_case_name| is name of test case, that should be used to report all
  384. // metrics.
  385. // |reporter_helper| is a pointer to a class that will allow track_id to
  386. // stream_id matching. The caller is responsible for ensuring the
  387. // TrackIdStreamInfoMap will be valid from Start() to
  388. // StopAndReportResults().
  389. virtual void Start(absl::string_view test_case_name,
  390. const TrackIdStreamInfoMap* reporter_helper) = 0;
  391. // Invoked by framework after call is ended and peer connection factory and
  392. // peer connection are destroyed.
  393. virtual void StopAndReportResults() = 0;
  394. };
  395. virtual ~PeerConnectionE2EQualityTestFixture() = default;
  396. // Add activity that will be executed on the best effort at least after
  397. // |target_time_since_start| after call will be set up (after offer/answer
  398. // exchange, ICE gathering will be done and ICE candidates will passed to
  399. // remote side). |func| param is amount of time spent from the call set up.
  400. virtual void ExecuteAt(TimeDelta target_time_since_start,
  401. std::function<void(TimeDelta)> func) = 0;
  402. // Add activity that will be executed every |interval| with first execution
  403. // on the best effort at least after |initial_delay_since_start| after call
  404. // will be set up (after all participants will be connected). |func| param is
  405. // amount of time spent from the call set up.
  406. virtual void ExecuteEvery(TimeDelta initial_delay_since_start,
  407. TimeDelta interval,
  408. std::function<void(TimeDelta)> func) = 0;
  409. // Add stats reporter entity to observe the test.
  410. virtual void AddQualityMetricsReporter(
  411. std::unique_ptr<QualityMetricsReporter> quality_metrics_reporter) = 0;
  412. // Add a new peer to the call and return an object through which caller
  413. // can configure peer's behavior.
  414. // |network_thread| will be used as network thread for peer's peer connection
  415. // |network_manager| will be used to provide network interfaces for peer's
  416. // peer connection.
  417. // |configurer| function will be used to configure peer in the call.
  418. virtual void AddPeer(rtc::Thread* network_thread,
  419. rtc::NetworkManager* network_manager,
  420. rtc::FunctionView<void(PeerConfigurer*)> configurer) = 0;
  421. // Runs the media quality test, which includes setting up the call with
  422. // configured participants, running it according to provided |run_params| and
  423. // terminating it properly at the end. During call duration media quality
  424. // metrics are gathered, which are then reported to stdout and (if configured)
  425. // to the json/protobuf output file through the WebRTC perf test results
  426. // reporting system.
  427. virtual void Run(RunParams run_params) = 0;
  428. // Returns real test duration - the time of test execution measured during
  429. // test. Client must call this method only after test is finished (after
  430. // Run(...) method returned). Test execution time is time from end of call
  431. // setup (offer/answer, ICE candidates exchange done and ICE connected) to
  432. // start of call tear down (PeerConnection closed).
  433. virtual TimeDelta GetRealTestDuration() const = 0;
  434. };
  435. } // namespace webrtc_pc_e2e
  436. } // namespace webrtc
  437. #endif // API_TEST_PEERCONNECTION_QUALITY_TEST_FIXTURE_H_