peer_configurer.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * Copyright (c) 2019 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 TEST_PC_E2E_PEER_CONFIGURER_H_
  11. #define TEST_PC_E2E_PEER_CONFIGURER_H_
  12. #include <memory>
  13. #include <string>
  14. #include <utility>
  15. #include <vector>
  16. #include "absl/strings/string_view.h"
  17. #include "api/async_resolver_factory.h"
  18. #include "api/call/call_factory_interface.h"
  19. #include "api/fec_controller.h"
  20. #include "api/rtc_event_log/rtc_event_log_factory_interface.h"
  21. #include "api/task_queue/task_queue_factory.h"
  22. #include "api/test/create_peer_connection_quality_test_frame_generator.h"
  23. #include "api/test/peerconnection_quality_test_fixture.h"
  24. #include "api/transport/network_control.h"
  25. #include "api/video_codecs/video_decoder_factory.h"
  26. #include "api/video_codecs/video_encoder_factory.h"
  27. #include "rtc_base/network.h"
  28. #include "rtc_base/rtc_certificate_generator.h"
  29. #include "rtc_base/ssl_certificate.h"
  30. #include "rtc_base/thread.h"
  31. #include "test/pc/e2e/peer_connection_quality_test_params.h"
  32. namespace webrtc {
  33. namespace webrtc_pc_e2e {
  34. class PeerConfigurerImpl final
  35. : public PeerConnectionE2EQualityTestFixture::PeerConfigurer {
  36. public:
  37. using VideoSource =
  38. absl::variant<std::unique_ptr<test::FrameGeneratorInterface>,
  39. PeerConnectionE2EQualityTestFixture::CapturingDeviceIndex>;
  40. PeerConfigurerImpl(rtc::Thread* network_thread,
  41. rtc::NetworkManager* network_manager)
  42. : components_(std::make_unique<InjectableComponents>(network_thread,
  43. network_manager)),
  44. params_(std::make_unique<Params>()) {}
  45. PeerConfigurer* SetName(absl::string_view name) override {
  46. params_->name = std::string(name);
  47. return this;
  48. }
  49. // Implementation of PeerConnectionE2EQualityTestFixture::PeerConfigurer.
  50. PeerConfigurer* SetTaskQueueFactory(
  51. std::unique_ptr<TaskQueueFactory> task_queue_factory) override {
  52. components_->pcf_dependencies->task_queue_factory =
  53. std::move(task_queue_factory);
  54. return this;
  55. }
  56. PeerConfigurer* SetCallFactory(
  57. std::unique_ptr<CallFactoryInterface> call_factory) override {
  58. components_->pcf_dependencies->call_factory = std::move(call_factory);
  59. return this;
  60. }
  61. PeerConfigurer* SetEventLogFactory(
  62. std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory) override {
  63. components_->pcf_dependencies->event_log_factory =
  64. std::move(event_log_factory);
  65. return this;
  66. }
  67. PeerConfigurer* SetFecControllerFactory(
  68. std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory)
  69. override {
  70. components_->pcf_dependencies->fec_controller_factory =
  71. std::move(fec_controller_factory);
  72. return this;
  73. }
  74. PeerConfigurer* SetNetworkControllerFactory(
  75. std::unique_ptr<NetworkControllerFactoryInterface>
  76. network_controller_factory) override {
  77. components_->pcf_dependencies->network_controller_factory =
  78. std::move(network_controller_factory);
  79. return this;
  80. }
  81. PeerConfigurer* SetVideoEncoderFactory(
  82. std::unique_ptr<VideoEncoderFactory> video_encoder_factory) override {
  83. components_->pcf_dependencies->video_encoder_factory =
  84. std::move(video_encoder_factory);
  85. return this;
  86. }
  87. PeerConfigurer* SetVideoDecoderFactory(
  88. std::unique_ptr<VideoDecoderFactory> video_decoder_factory) override {
  89. components_->pcf_dependencies->video_decoder_factory =
  90. std::move(video_decoder_factory);
  91. return this;
  92. }
  93. PeerConfigurer* SetAsyncResolverFactory(
  94. std::unique_ptr<webrtc::AsyncResolverFactory> async_resolver_factory)
  95. override {
  96. components_->pc_dependencies->async_resolver_factory =
  97. std::move(async_resolver_factory);
  98. return this;
  99. }
  100. PeerConfigurer* SetRTCCertificateGenerator(
  101. std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator)
  102. override {
  103. components_->pc_dependencies->cert_generator = std::move(cert_generator);
  104. return this;
  105. }
  106. PeerConfigurer* SetSSLCertificateVerifier(
  107. std::unique_ptr<rtc::SSLCertificateVerifier> tls_cert_verifier) override {
  108. components_->pc_dependencies->tls_cert_verifier =
  109. std::move(tls_cert_verifier);
  110. return this;
  111. }
  112. PeerConfigurer* AddVideoConfig(
  113. PeerConnectionE2EQualityTestFixture::VideoConfig config) override {
  114. video_sources_.push_back(
  115. CreateSquareFrameGenerator(config, /*type=*/absl::nullopt));
  116. params_->video_configs.push_back(std::move(config));
  117. return this;
  118. }
  119. PeerConfigurer* AddVideoConfig(
  120. PeerConnectionE2EQualityTestFixture::VideoConfig config,
  121. std::unique_ptr<test::FrameGeneratorInterface> generator) override {
  122. params_->video_configs.push_back(std::move(config));
  123. video_sources_.push_back(std::move(generator));
  124. return this;
  125. }
  126. PeerConfigurer* AddVideoConfig(
  127. PeerConnectionE2EQualityTestFixture::VideoConfig config,
  128. PeerConnectionE2EQualityTestFixture::CapturingDeviceIndex index)
  129. override {
  130. params_->video_configs.push_back(std::move(config));
  131. video_sources_.push_back(index);
  132. return this;
  133. }
  134. PeerConfigurer* SetAudioConfig(
  135. PeerConnectionE2EQualityTestFixture::AudioConfig config) override {
  136. params_->audio_config = std::move(config);
  137. return this;
  138. }
  139. PeerConfigurer* SetNetEqFactory(
  140. std::unique_ptr<NetEqFactory> neteq_factory) override {
  141. components_->pcf_dependencies->neteq_factory = std::move(neteq_factory);
  142. return this;
  143. }
  144. PeerConfigurer* SetRtcEventLogPath(std::string path) override {
  145. params_->rtc_event_log_path = std::move(path);
  146. return this;
  147. }
  148. PeerConfigurer* SetAecDumpPath(std::string path) override {
  149. params_->aec_dump_path = std::move(path);
  150. return this;
  151. }
  152. PeerConfigurer* SetRTCConfiguration(
  153. PeerConnectionInterface::RTCConfiguration configuration) override {
  154. params_->rtc_configuration = std::move(configuration);
  155. return this;
  156. }
  157. PeerConfigurer* SetBitrateSettings(
  158. BitrateSettings bitrate_settings) override {
  159. params_->bitrate_settings = bitrate_settings;
  160. return this;
  161. }
  162. PeerConfigurer* SetIceTransportFactory(
  163. std::unique_ptr<IceTransportFactory> factory) override {
  164. components_->pc_dependencies->ice_transport_factory = std::move(factory);
  165. return this;
  166. }
  167. // Implementation of PeerConnectionE2EQualityTestFixture::PeerConfigurer end.
  168. InjectableComponents* components() { return components_.get(); }
  169. Params* params() { return params_.get(); }
  170. std::vector<VideoSource>* video_sources() { return &video_sources_; }
  171. // Returns InjectableComponents and transfer ownership to the caller.
  172. // Can be called once.
  173. std::unique_ptr<InjectableComponents> ReleaseComponents() {
  174. RTC_CHECK(components_);
  175. auto components = std::move(components_);
  176. components_ = nullptr;
  177. return components;
  178. }
  179. // Returns Params and transfer ownership to the caller.
  180. // Can be called once.
  181. std::unique_ptr<Params> ReleaseParams() {
  182. RTC_CHECK(params_);
  183. auto params = std::move(params_);
  184. params_ = nullptr;
  185. return params;
  186. }
  187. // Returns video sources and transfer frame generators ownership to the
  188. // caller. Can be called once.
  189. std::vector<VideoSource> ReleaseVideoSources() {
  190. auto video_sources = std::move(video_sources_);
  191. video_sources_.clear();
  192. return video_sources;
  193. }
  194. private:
  195. std::unique_ptr<InjectableComponents> components_;
  196. std::unique_ptr<Params> params_;
  197. std::vector<VideoSource> video_sources_;
  198. };
  199. // Set missing params to default values if it is required:
  200. // * Generate video stream labels if some of them are missing
  201. // * Generate audio stream labels if some of them are missing
  202. // * Set video source generation mode if it is not specified
  203. // * Video codecs under test
  204. void SetDefaultValuesForMissingParams(
  205. PeerConnectionE2EQualityTestFixture::RunParams* run_params,
  206. std::vector<std::unique_ptr<PeerConfigurerImpl>>* peers);
  207. // Validate peer's parameters, also ensure uniqueness of all video stream
  208. // labels.
  209. void ValidateParams(
  210. const PeerConnectionE2EQualityTestFixture::RunParams& run_params,
  211. const std::vector<std::unique_ptr<PeerConfigurerImpl>>& peers);
  212. } // namespace webrtc_pc_e2e
  213. } // namespace webrtc
  214. #endif // TEST_PC_E2E_PEER_CONFIGURER_H_