diff --git a/test/pc/e2e/media/media_helper.cc b/test/pc/e2e/media/media_helper.cc index c5c5a10a32..22fcc51ffe 100644 --- a/test/pc/e2e/media/media_helper.cc +++ b/test/pc/e2e/media/media_helper.cc @@ -52,9 +52,10 @@ std::vector> MediaHelper::MaybeAddVideo(TestPeer* peer) { // Params here valid because of pre-run validation. const Params& params = peer->params(); + const ConfigurableParams& configurable_params = peer->configurable_params(); std::vector> out; - for (size_t i = 0; i < params.video_configs.size(); ++i) { - auto video_config = params.video_configs[i]; + for (size_t i = 0; i < configurable_params.video_configs.size(); ++i) { + const VideoConfig& video_config = configurable_params.video_configs[i]; // Setup input video source into peer connection. std::unique_ptr capturer = CreateVideoCapturer( video_config, peer->ReleaseVideoSource(i), diff --git a/test/pc/e2e/peer_configurer.cc b/test/pc/e2e/peer_configurer.cc index a903c86322..688aa0efde 100644 --- a/test/pc/e2e/peer_configurer.cc +++ b/test/pc/e2e/peer_configurer.cc @@ -65,21 +65,27 @@ PeerParamsPreprocessor::PeerParamsPreprocessor() void PeerParamsPreprocessor::SetDefaultValuesForMissingParams( PeerConfigurerImpl& peer) { - auto* p = peer.params(); - peer_names_provider.MaybeSetName(p->name); - DefaultNamesProvider video_stream_names_provider(*p->name + + Params* params = peer.params(); + ConfigurableParams* configurable_params = peer.configurable_params(); + peer_names_provider.MaybeSetName(params->name); + DefaultNamesProvider video_stream_names_provider(*params->name + "_auto_video_stream_label_"); - for (VideoConfig& video_config : p->video_configs) { - video_stream_names_provider.MaybeSetName(video_config.stream_label); + for (size_t i = 0; i < configurable_params->video_configs.size(); ++i) { + video_stream_names_provider.MaybeSetName( + configurable_params->video_configs[i].stream_label); + // TODO(titovartem): remove when downstream will migrate on new API. + params->video_configs[i].stream_label = + configurable_params->video_configs[i].stream_label; } - if (p->audio_config) { + if (params->audio_config) { DefaultNamesProvider audio_stream_names_provider( - *p->name + "_auto_audio_stream_label_"); - audio_stream_names_provider.MaybeSetName(p->audio_config->stream_label); + *params->name + "_auto_audio_stream_label_"); + audio_stream_names_provider.MaybeSetName( + params->audio_config->stream_label); } - if (p->video_codecs.empty()) { - p->video_codecs.push_back( + if (params->video_codecs.empty()) { + params->video_codecs.push_back( PeerConnectionE2EQualityTestFixture::VideoCodecConfig( cricket::kVp8CodecName)); } @@ -100,11 +106,12 @@ void PeerParamsPreprocessor::ValidateParams(const PeerConfigurerImpl& peer) { if (p.audio_config) { media_streams_count++; } - media_streams_count += p.video_configs.size(); + media_streams_count += peer.configurable_params().video_configs.size(); // Validate that all video stream labels are unique and sync groups are // valid. - for (const VideoConfig& video_config : p.video_configs) { + for (const VideoConfig& video_config : + peer.configurable_params().video_configs) { RTC_CHECK(video_config.stream_label); bool inserted = video_labels.insert(video_config.stream_label.value()).second; diff --git a/test/pc/e2e/peer_configurer.h b/test/pc/e2e/peer_configurer.h index ee3c992b42..0c13380a5b 100644 --- a/test/pc/e2e/peer_configurer.h +++ b/test/pc/e2e/peer_configurer.h @@ -51,7 +51,8 @@ class PeerConfigurerImpl final std::make_unique(network_thread, network_manager, packet_socket_factory)), - params_(std::make_unique()) {} + params_(std::make_unique()), + configurable_params_(std::make_unique()) {} PeerConfigurer* SetName(absl::string_view name) override { params_->name = std::string(name); @@ -127,13 +128,17 @@ class PeerConfigurerImpl final PeerConnectionE2EQualityTestFixture::VideoConfig config) override { video_sources_.push_back( CreateSquareFrameGenerator(config, /*type=*/absl::nullopt)); - params_->video_configs.push_back(std::move(config)); + // TODO(titovartem): remove when downstream will migrate on new API. + params_->video_configs.push_back(config); + configurable_params_->video_configs.push_back(std::move(config)); return this; } PeerConfigurer* AddVideoConfig( PeerConnectionE2EQualityTestFixture::VideoConfig config, std::unique_ptr generator) override { - params_->video_configs.push_back(std::move(config)); + // TODO(titovartem): remove when downstream will migrate on new API. + params_->video_configs.push_back(config); + configurable_params_->video_configs.push_back(std::move(config)); video_sources_.push_back(std::move(generator)); return this; } @@ -141,14 +146,18 @@ class PeerConfigurerImpl final PeerConnectionE2EQualityTestFixture::VideoConfig config, PeerConnectionE2EQualityTestFixture::CapturingDeviceIndex index) override { - params_->video_configs.push_back(std::move(config)); + // TODO(titovartem): remove when downstream will migrate on new API. + params_->video_configs.push_back(config); + configurable_params_->video_configs.push_back(std::move(config)); video_sources_.push_back(index); return this; } PeerConfigurer* SetVideoSubscription( PeerConnectionE2EQualityTestFixture::VideoSubscription subscription) override { - params_->video_subscription = std::move(subscription); + // TODO(titovartem): remove when downstream will migrate on new API. + params_->video_subscription = subscription; + configurable_params_->video_subscription = std::move(subscription); return this; } PeerConfigurer* SetAudioConfig( @@ -227,7 +236,13 @@ class PeerConfigurerImpl final InjectableComponents* components() { return components_.get(); } Params* params() { return params_.get(); } + ConfigurableParams* configurable_params() { + return configurable_params_.get(); + } const Params& params() const { return *params_; } + const ConfigurableParams& configurable_params() const { + return *configurable_params_; + } std::vector* video_sources() { return &video_sources_; } // Returns InjectableComponents and transfer ownership to the caller. @@ -238,6 +253,7 @@ class PeerConfigurerImpl final components_ = nullptr; return components; } + // Returns Params and transfer ownership to the caller. // Can be called once. std::unique_ptr ReleaseParams() { @@ -246,6 +262,16 @@ class PeerConfigurerImpl final params_ = nullptr; return params; } + + // Returns ConfigurableParams and transfer ownership to the caller. + // Can be called once. + std::unique_ptr ReleaseConfigurableParams() { + RTC_CHECK(configurable_params_); + auto configurable_params = std::move(configurable_params_); + configurable_params_ = nullptr; + return configurable_params; + } + // Returns video sources and transfer frame generators ownership to the // caller. Can be called once. std::vector ReleaseVideoSources() { @@ -257,6 +283,7 @@ class PeerConfigurerImpl final private: std::unique_ptr components_; std::unique_ptr params_; + std::unique_ptr configurable_params_; std::vector video_sources_; }; diff --git a/test/pc/e2e/peer_connection_quality_test.cc b/test/pc/e2e/peer_connection_quality_test.cc index 3b61183111..b72369b285 100644 --- a/test/pc/e2e/peer_connection_quality_test.cc +++ b/test/pc/e2e/peer_connection_quality_test.cc @@ -106,11 +106,12 @@ class FixturePeerConnectionObserver : public MockPeerConnectionObserver { void ValidateP2PSimulcastParams( const std::vector>& peers) { for (size_t i = 0; i < peers.size(); ++i) { - Params* p = peers[i]->params(); - for (const VideoConfig& video_config : p->video_configs) { + Params* params = peers[i]->params(); + ConfigurableParams* configurable_params = peers[i]->configurable_params(); + for (const VideoConfig& video_config : configurable_params->video_configs) { if (video_config.simulcast_config) { // When we simulate SFU we support only one video codec. - RTC_CHECK_EQ(p->video_codecs.size(), 1) + RTC_CHECK_EQ(params->video_codecs.size(), 1) << "Only 1 video codec is supported when simulcast is enabled in " << "at least 1 video config"; } @@ -196,27 +197,28 @@ void PeerConnectionE2EQualityTest::Run(RunParams run_params) { std::move(peer_configurations_[1]); peer_configurations_.clear(); - for (size_t i = 0; i < bob_configurer->params()->video_configs.size(); ++i) { + for (size_t i = 0; + i < bob_configurer->configurable_params()->video_configs.size(); ++i) { // We support simulcast only from caller. - RTC_CHECK(!bob_configurer->params()->video_configs[i].simulcast_config) + RTC_CHECK(!bob_configurer->configurable_params() + ->video_configs[i] + .simulcast_config) << "Only simulcast stream from first peer is supported"; } test::ScopedFieldTrials field_trials(GetFieldTrials(run_params)); // Print test summary - RTC_LOG(LS_INFO) << "Media quality test: " - << *alice_configurer->params()->name - << " will make a call to " << *bob_configurer->params()->name - << " with media video=" - << !alice_configurer->params()->video_configs.empty() - << "; audio=" - << alice_configurer->params()->audio_config.has_value() - << ". " << *bob_configurer->params()->name - << " will respond with media video=" - << !bob_configurer->params()->video_configs.empty() - << "; audio=" - << bob_configurer->params()->audio_config.has_value(); + RTC_LOG(LS_INFO) + << "Media quality test: " << *alice_configurer->params()->name + << " will make a call to " << *bob_configurer->params()->name + << " with media video=" + << !alice_configurer->configurable_params()->video_configs.empty() + << "; audio=" << alice_configurer->params()->audio_config.has_value() + << ". " << *bob_configurer->params()->name + << " will respond with media video=" + << !bob_configurer->configurable_params()->video_configs.empty() + << "; audio=" << bob_configurer->params()->audio_config.has_value(); const std::unique_ptr signaling_thread = time_controller_.CreateThread(kSignalThreadName); @@ -240,10 +242,10 @@ void PeerConnectionE2EQualityTest::Run(RunParams run_params) { // Copy Alice and Bob video configs and names to correctly pass them into // lambdas. std::vector alice_video_configs = - alice_configurer->params()->video_configs; + alice_configurer->configurable_params()->video_configs; std::string alice_name = alice_configurer->params()->name.value(); std::vector bob_video_configs = - bob_configurer->params()->video_configs; + bob_configurer->configurable_params()->video_configs; std::string bob_name = bob_configurer->params()->name.value(); TestPeerFactory test_peer_factory( @@ -468,7 +470,7 @@ void PeerConnectionE2EQualityTest::SetupCallOnSignalingThread( } size_t alice_video_transceivers_non_simulcast_counter = 0; - for (auto& video_config : alice_->params().video_configs) { + for (auto& video_config : alice_->configurable_params().video_configs) { RtpTransceiverInit transceiver_params; if (video_config.simulcast_config) { transceiver_params.direction = RtpTransceiverDirection::kSendOnly; @@ -510,7 +512,7 @@ void PeerConnectionE2EQualityTest::SetupCallOnSignalingThread( // Add receive only transceivers in case Bob has more video_configs than // Alice. for (size_t i = alice_video_transceivers_non_simulcast_counter; - i < bob_->params().video_configs.size(); ++i) { + i < bob_->configurable_params().video_configs.size(); ++i) { RTCErrorOr> result = alice_->AddTransceiver(cricket::MediaType::MEDIA_TYPE_VIDEO, receive_only_transceiver_init); @@ -572,7 +574,7 @@ PeerConnectionE2EQualityTest::CreateSignalingInterceptor( std::map stream_label_to_simulcast_streams_count; // We add only Alice here, because simulcast/svc is supported only from the // first peer. - for (auto& video_config : alice_->params().video_configs) { + for (auto& video_config : alice_->configurable_params().video_configs) { if (video_config.simulcast_config) { stream_label_to_simulcast_streams_count.insert( {*video_config.stream_label, diff --git a/test/pc/e2e/peer_connection_quality_test_params.h b/test/pc/e2e/peer_connection_quality_test_params.h index 5a2431ab88..d49140f493 100644 --- a/test/pc/e2e/peer_connection_quality_test_params.h +++ b/test/pc/e2e/peer_connection_quality_test_params.h @@ -115,6 +115,7 @@ struct Params { // Peer name. If empty - default one will be set by the fixture. absl::optional name; // If `video_configs` is empty - no video should be added to the test call. + // TODO(titovartem): remove when downstream will migrate on new API. std::vector video_configs; // If `audio_config` is set audio stream will be configured absl::optional audio_config; @@ -143,6 +144,18 @@ struct Params { BitrateSettings bitrate_settings; std::vector video_codecs; + + // TODO(titovartem): remove when downstream will migrate on new API. + PeerConnectionE2EQualityTestFixture::VideoSubscription video_subscription = + PeerConnectionE2EQualityTestFixture::VideoSubscription() + .SubscribeToAllPeers(); +}; + +// Contains parameters that maybe changed by test writer during the test call. +struct ConfigurableParams { + // If `video_configs` is empty - no video should be added to the test call. + std::vector video_configs; + PeerConnectionE2EQualityTestFixture::VideoSubscription video_subscription = PeerConnectionE2EQualityTestFixture::VideoSubscription() .SubscribeToAllPeers(); diff --git a/test/pc/e2e/test_peer.cc b/test/pc/e2e/test_peer.cc index 02bbafc21a..bf552ddf06 100644 --- a/test/pc/e2e/test_peer.cc +++ b/test/pc/e2e/test_peer.cc @@ -91,11 +91,13 @@ TestPeer::TestPeer( rtc::scoped_refptr pc_factory, rtc::scoped_refptr pc, std::unique_ptr observer, - std::unique_ptr params, + Params params, + ConfigurableParams configurable_params, std::vector video_sources, rtc::scoped_refptr audio_processing, std::unique_ptr worker_thread) - : params_(std::move(*params)), + : params_(std::move(params)), + configurable_params_(std::move(configurable_params)), worker_thread_(std::move(worker_thread)), wrapper_(std::make_unique(std::move(pc_factory), std::move(pc), diff --git a/test/pc/e2e/test_peer.h b/test/pc/e2e/test_peer.h index 7c199e8345..66784b8087 100644 --- a/test/pc/e2e/test_peer.h +++ b/test/pc/e2e/test_peer.h @@ -34,6 +34,9 @@ namespace webrtc_pc_e2e { class TestPeer final { public: const Params& params() const { return params_; } + ConfigurableParams configurable_params() const { + return configurable_params_; + } // TODO(titovartem): delete when downstreams will migrate to the new method. const Params& params2() const { return params_; } @@ -143,13 +146,15 @@ class TestPeer final { TestPeer(rtc::scoped_refptr pc_factory, rtc::scoped_refptr pc, std::unique_ptr observer, - std::unique_ptr params, + Params params, + ConfigurableParams configurable_params, std::vector video_sources, rtc::scoped_refptr audio_processing, std::unique_ptr worker_thread); private: Params params_; + ConfigurableParams configurable_params_; // Keeps ownership of worker thread. It has to be destroyed after `wrapper_`. std::unique_ptr worker_thread_; std::unique_ptr wrapper_; diff --git a/test/pc/e2e/test_peer_factory.cc b/test/pc/e2e/test_peer_factory.cc index 29a4c6a8f2..01388d90ea 100644 --- a/test/pc/e2e/test_peer_factory.cc +++ b/test/pc/e2e/test_peer_factory.cc @@ -306,11 +306,15 @@ std::unique_ptr TestPeerFactory::CreateTestPeer( std::unique_ptr components = configurer->ReleaseComponents(); std::unique_ptr params = configurer->ReleaseParams(); + std::unique_ptr configurable_params = + configurer->ReleaseConfigurableParams(); std::vector video_sources = configurer->ReleaseVideoSources(); RTC_DCHECK(components); RTC_DCHECK(params); - RTC_DCHECK_EQ(params->video_configs.size(), video_sources.size()); + RTC_DCHECK(configurable_params); + RTC_DCHECK_EQ(configurable_params->video_configs.size(), + video_sources.size()); SetMandatoryEntities(components.get(), time_controller_); params->rtc_configuration.sdp_semantics = SdpSemantics::kUnifiedPlan; @@ -329,7 +333,8 @@ std::unique_ptr TestPeerFactory::CreateTestPeer( components->pcf_dependencies->task_queue_factory.get()); WrapVideoEncoderFactory( params->name.value(), params->video_encoder_bitrate_multiplier, - CalculateRequiredSpatialIndexPerStream(params->video_configs), + CalculateRequiredSpatialIndexPerStream( + configurable_params->video_configs), components->pcf_dependencies.get(), video_analyzer_helper_); WrapVideoDecoderFactory(params->name.value(), components->pcf_dependencies.get(), @@ -363,8 +368,8 @@ std::unique_ptr TestPeerFactory::CreateTestPeer( return absl::WrapUnique(new TestPeer( peer_connection_factory, peer_connection, std::move(observer), - std::move(params), std::move(video_sources), audio_processing, - std::move(worker_thread))); + std::move(*params), std::move(*configurable_params), + std::move(video_sources), audio_processing, std::move(worker_thread))); } } // namespace webrtc_pc_e2e