peer_configurer.h 8.8 KB

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