diff --git a/call/BUILD.gn b/call/BUILD.gn index 39ae7692fb..9a7be88892 100644 --- a/call/BUILD.gn +++ b/call/BUILD.gn @@ -569,7 +569,6 @@ if (rtc_include_tests) { "../api/rtc_event_log", "../api/rtc_event_log:rtc_event_log_factory", "../api/task_queue", - "../api/task_queue:default_task_queue_factory", "../api/task_queue:pending_task_safety_flag", "../api/test/metrics:global_metrics_logger_and_exporter", "../api/test/metrics:metric", diff --git a/call/bitrate_estimator_tests.cc b/call/bitrate_estimator_tests.cc index f17a037ed2..d945dfccca 100644 --- a/call/bitrate_estimator_tests.cc +++ b/call/bitrate_estimator_tests.cc @@ -178,13 +178,13 @@ class BitrateEstimatorTest : public test::CallTest { RTC_DCHECK_EQ(1, test_->GetVideoEncoderConfig()->number_of_streams); frame_generator_capturer_ = std::make_unique( - test->clock_, + &test->env().clock(), test::CreateSquareFrameGenerator( test::VideoTestConstants::kDefaultWidth, test::VideoTestConstants::kDefaultHeight, absl::nullopt, absl::nullopt), test::VideoTestConstants::kDefaultFramerate, - *test->task_queue_factory_); + test->env().task_queue_factory()); frame_generator_capturer_->Init(); frame_generator_capturer_->Start(); send_stream_->SetSource(frame_generator_capturer_.get(), diff --git a/call/call_perf_tests.cc b/call/call_perf_tests.cc index 0ba6d05b19..e3939e1371 100644 --- a/call/call_perf_tests.cc +++ b/call/call_perf_tests.cc @@ -212,7 +212,7 @@ void CallPerfTest::TestAudioVideoSync(FecMode fec, metrics::Reset(); rtc::scoped_refptr fake_audio_device = TestAudioDeviceModule::Create( - task_queue_factory_.get(), + &env().task_queue_factory(), TestAudioDeviceModule::CreatePulsedNoiseCapturer(256, 48000), TestAudioDeviceModule::CreateDiscardRenderer(48000), audio_rtp_speed); @@ -223,12 +223,12 @@ void CallPerfTest::TestAudioVideoSync(FecMode fec, send_audio_state_config.audio_processing = AudioProcessingBuilder().Create(); send_audio_state_config.audio_device_module = fake_audio_device; - CallConfig sender_config(send_event_log_.get()); + CallConfig sender_config = SendCallConfig(); auto audio_state = AudioState::Create(send_audio_state_config); fake_audio_device->RegisterAudioCallback(audio_state->audio_transport()); sender_config.audio_state = audio_state; - CallConfig receiver_config(recv_event_log_.get()); + CallConfig receiver_config = RecvCallConfig(); receiver_config.audio_state = audio_state; CreateCalls(sender_config, receiver_config); @@ -319,7 +319,8 @@ void CallPerfTest::TestAudioVideoSync(FecMode fec, } EXPECT_EQ(1u, video_receive_streams_.size()); observer->set_receive_stream(video_receive_streams_[0]); - drifting_clock = std::make_unique(clock_, video_ntp_speed); + drifting_clock = + std::make_unique(&env().clock(), video_ntp_speed); CreateFrameGeneratorCapturerWithDrift( drifting_clock.get(), video_rtp_speed, test::VideoTestConstants::kDefaultFramerate, diff --git a/call/rampup_tests.cc b/call/rampup_tests.cc index 232fe0b3fe..66553f2674 100644 --- a/call/rampup_tests.cc +++ b/call/rampup_tests.cc @@ -16,9 +16,7 @@ #include "absl/strings/string_view.h" #include "api/rtc_event_log/rtc_event_log_factory.h" #include "api/rtc_event_log_output_file.h" -#include "api/task_queue/default_task_queue_factory.h" #include "api/task_queue/task_queue_base.h" -#include "api/task_queue/task_queue_factory.h" #include "api/test/metrics/global_metrics_logger_and_exporter.h" #include "api/test/metrics/metric.h" #include "call/fake_network_pipe.h" @@ -565,30 +563,29 @@ void RampUpDownUpTester::EvolveTestState(int bitrate_bps, bool suspended) { class RampUpTest : public test::CallTest { public: - RampUpTest() - : task_queue_factory_(CreateDefaultTaskQueueFactory()), - rtc_event_log_factory_(task_queue_factory_.get()) { + RampUpTest() { std::string dump_name(absl::GetFlag(FLAGS_ramp_dump_name)); if (!dump_name.empty()) { - send_event_log_ = rtc_event_log_factory_.CreateRtcEventLog( - RtcEventLog::EncodingType::Legacy); - recv_event_log_ = rtc_event_log_factory_.CreateRtcEventLog( - RtcEventLog::EncodingType::Legacy); + std::unique_ptr send_event_log = + rtc_event_log_factory_.Create(env()); + std::unique_ptr recv_event_log = + rtc_event_log_factory_.Create(env()); bool event_log_started = - send_event_log_->StartLogging( + send_event_log->StartLogging( std::make_unique( dump_name + ".send.rtc.dat", RtcEventLog::kUnlimitedOutput), RtcEventLog::kImmediateOutput) && - recv_event_log_->StartLogging( + recv_event_log->StartLogging( std::make_unique( dump_name + ".recv.rtc.dat", RtcEventLog::kUnlimitedOutput), RtcEventLog::kImmediateOutput); RTC_DCHECK(event_log_started); + SetSendEventLog(std::move(send_event_log)); + SetRecvEventLog(std::move(recv_event_log)); } } private: - const std::unique_ptr task_queue_factory_; RtcEventLogFactory rtc_event_log_factory_; }; diff --git a/test/BUILD.gn b/test/BUILD.gn index e0afa27cec..d313c6d82d 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -1287,9 +1287,10 @@ if (!build_with_chromium) { "../api:transport_api", "../api/audio_codecs:builtin_audio_decoder_factory", "../api/audio_codecs:builtin_audio_encoder_factory", + "../api/environment", + "../api/environment:environment_factory", "../api/rtc_event_log", "../api/task_queue", - "../api/task_queue:default_task_queue_factory", "../api/test/video:function_video_factory", "../api/transport:field_trial_based_config", "../api/units:time_delta", diff --git a/test/call_test.cc b/test/call_test.cc index 2b71608ac6..09099cccd6 100644 --- a/test/call_test.cc +++ b/test/call_test.cc @@ -15,7 +15,8 @@ #include "api/audio_codecs/builtin_audio_decoder_factory.h" #include "api/audio_codecs/builtin_audio_encoder_factory.h" -#include "api/task_queue/default_task_queue_factory.h" +#include "api/environment/environment.h" +#include "api/environment/environment_factory.h" #include "api/task_queue/task_queue_base.h" #include "api/test/create_frame_generator.h" #include "api/video/builtin_video_bitrate_allocator_factory.h" @@ -38,19 +39,18 @@ namespace webrtc { namespace test { CallTest::CallTest() - : clock_(Clock::GetRealTimeClock()), - task_queue_factory_(CreateDefaultTaskQueueFactory()), - send_event_log_(std::make_unique()), - recv_event_log_(std::make_unique()), + : env_(CreateEnvironment(&field_trials_)), + send_env_(env_), + recv_env_(env_), audio_send_config_(/*send_transport=*/nullptr), audio_send_stream_(nullptr), frame_generator_capturer_(nullptr), fake_encoder_factory_([this]() { std::unique_ptr fake_encoder; if (video_encoder_configs_[0].codec_type == kVideoCodecVP8) { - fake_encoder = std::make_unique(clock_); + fake_encoder = std::make_unique(&env_.clock()); } else { - fake_encoder = std::make_unique(clock_); + fake_encoder = std::make_unique(&env_.clock()); } fake_encoder->SetMaxBitrate(fake_encoder_max_bitrate_); return fake_encoder; @@ -62,12 +62,24 @@ CallTest::CallTest() num_flexfec_streams_(0), audio_decoder_factory_(CreateBuiltinAudioDecoderFactory()), audio_encoder_factory_(CreateBuiltinAudioEncoderFactory()), - task_queue_(task_queue_factory_->CreateTaskQueue( + task_queue_(env_.task_queue_factory().CreateTaskQueue( "CallTestTaskQueue", TaskQueueFactory::Priority::NORMAL)) {} CallTest::~CallTest() = default; +void CallTest::SetSendEventLog(std::unique_ptr event_log) { + EnvironmentFactory f(env_); + f.Set(std::move(event_log)); + send_env_ = f.Create(); +} + +void CallTest::SetRecvEventLog(std::unique_ptr event_log) { + EnvironmentFactory f(env_); + f.Set(std::move(event_log)); + recv_env_ = f.Create(); +} + void CallTest::RegisterRtpExtension(const RtpExtension& extension) { for (const RtpExtension& registered_extension : rtp_extensions_) { if (registered_extension.id == extension.id) { @@ -97,7 +109,7 @@ void CallTest::RunBaseTest(BaseTest* test) { num_audio_streams_ = test->GetNumAudioStreams(); num_flexfec_streams_ = test->GetNumFlexfecStreams(); RTC_DCHECK(num_video_streams_ > 0 || num_audio_streams_ > 0); - CallConfig send_config(send_event_log_.get()); + CallConfig send_config = SendCallConfig(); test->ModifySenderBitrateConfig(&send_config.bitrate_config); if (num_audio_streams_ > 0) { CreateFakeAudioDevices(test->CreateCapturer(), test->CreateRenderer()); @@ -117,7 +129,7 @@ void CallTest::RunBaseTest(BaseTest* test) { } CreateSenderCall(send_config); if (test->ShouldCreateReceivers()) { - CallConfig recv_config(recv_event_log_.get()); + CallConfig recv_config = RecvCallConfig(); test->ModifyReceiverBitrateConfig(&recv_config.bitrate_config); if (num_audio_streams_ > 0) { AudioState::Config audio_state_config; @@ -206,9 +218,20 @@ void CallTest::RunBaseTest(BaseTest* test) { }); } +CallConfig CallTest::SendCallConfig() const { + CallConfig sender_config(send_env_); + sender_config.network_state_predictor_factory = + network_state_predictor_factory_.get(); + sender_config.network_controller_factory = network_controller_factory_.get(); + return sender_config; +} + +CallConfig CallTest::RecvCallConfig() const { + return CallConfig(recv_env_); +} + void CallTest::CreateCalls() { - CreateCalls(CallConfig(send_event_log_.get()), - CallConfig(recv_event_log_.get())); + CreateCalls(SendCallConfig(), RecvCallConfig()); } void CallTest::CreateCalls(const CallConfig& sender_config, @@ -218,24 +241,15 @@ void CallTest::CreateCalls(const CallConfig& sender_config, } void CallTest::CreateSenderCall() { - CreateSenderCall(CallConfig(send_event_log_.get())); + CreateSenderCall(SendCallConfig()); } void CallTest::CreateSenderCall(const CallConfig& config) { - auto sender_config = config; - sender_config.task_queue_factory = task_queue_factory_.get(); - sender_config.network_state_predictor_factory = - network_state_predictor_factory_.get(); - sender_config.network_controller_factory = network_controller_factory_.get(); - sender_config.trials = &field_trials_; - sender_call_ = Call::Create(sender_config); + sender_call_ = Call::Create(config); } void CallTest::CreateReceiverCall(const CallConfig& config) { - auto receiver_config = config; - receiver_config.task_queue_factory = task_queue_factory_.get(); - receiver_config.trials = &field_trials_; - receiver_call_ = Call::Create(receiver_config); + receiver_call_ = Call::Create(config); } void CallTest::DestroyCalls() { @@ -489,7 +503,7 @@ void CallTest::CreateFrameGeneratorCapturerWithDrift(Clock* clock, clock, test::CreateSquareFrameGenerator(width, height, absl::nullopt, absl::nullopt), - framerate * speed, *task_queue_factory_); + framerate * speed, env_.task_queue_factory()); frame_generator_capturer_ = frame_generator_capturer.get(); frame_generator_capturer->Init(); video_sources_.push_back(std::move(frame_generator_capturer)); @@ -502,10 +516,10 @@ void CallTest::CreateFrameGeneratorCapturer(int framerate, video_sources_.clear(); auto frame_generator_capturer = std::make_unique( - clock_, + &env_.clock(), test::CreateSquareFrameGenerator(width, height, absl::nullopt, absl::nullopt), - framerate, *task_queue_factory_); + framerate, env_.task_queue_factory()); frame_generator_capturer_ = frame_generator_capturer.get(); frame_generator_capturer->Init(); video_sources_.push_back(std::move(frame_generator_capturer)); @@ -516,9 +530,9 @@ void CallTest::CreateFakeAudioDevices( std::unique_ptr capturer, std::unique_ptr renderer) { fake_send_audio_device_ = TestAudioDeviceModule::Create( - task_queue_factory_.get(), std::move(capturer), nullptr, 1.f); + &env_.task_queue_factory(), std::move(capturer), nullptr, 1.f); fake_recv_audio_device_ = TestAudioDeviceModule::Create( - task_queue_factory_.get(), nullptr, std::move(renderer), 1.f); + &env_.task_queue_factory(), nullptr, std::move(renderer), 1.f); } void CallTest::CreateVideoStreams() { diff --git a/test/call_test.h b/test/call_test.h index 8d2b001f72..decf02f20b 100644 --- a/test/call_test.h +++ b/test/call_test.h @@ -17,6 +17,7 @@ #include "absl/types/optional.h" #include "api/array_view.h" +#include "api/environment/environment.h" #include "api/rtc_event_log/rtc_event_log.h" #include "api/task_queue/task_queue_base.h" #include "api/task_queue/task_queue_factory.h" @@ -52,6 +53,11 @@ class CallTest : public ::testing::Test, public RtpPacketSinkInterface { static const std::map payload_type_map_; protected: + const Environment& env() const { return env_; } + + void SetSendEventLog(std::unique_ptr event_log); + void SetRecvEventLog(std::unique_ptr event_log); + void RegisterRtpExtension(const RtpExtension& extension); // Returns header extensions that can be parsed by the transport. rtc::ArrayView GetRegisteredExtensions() { @@ -62,6 +68,9 @@ class CallTest : public ::testing::Test, public RtpPacketSinkInterface { // to simplify test code. void RunBaseTest(BaseTest* test); + CallConfig SendCallConfig() const; + CallConfig RecvCallConfig() const; + void CreateCalls(); void CreateCalls(const CallConfig& sender_config, const CallConfig& receiver_config); @@ -185,13 +194,11 @@ class CallTest : public ::testing::Test, public RtpPacketSinkInterface { void OnRtpPacket(const RtpPacketReceived& packet) override; test::RunLoop loop_; - - Clock* const clock_; test::ScopedKeyValueConfig field_trials_; + Environment env_; + Environment send_env_; + Environment recv_env_; - std::unique_ptr task_queue_factory_; - std::unique_ptr send_event_log_; - std::unique_ptr recv_event_log_; std::unique_ptr sender_call_; std::unique_ptr send_transport_; SimulatedNetworkInterface* send_simulated_network_ = nullptr; diff --git a/video/end_to_end_tests/network_state_tests.cc b/video/end_to_end_tests/network_state_tests.cc index 7bc9f1493e..7e9c86362a 100644 --- a/video/end_to_end_tests/network_state_tests.cc +++ b/video/end_to_end_tests/network_state_tests.cc @@ -94,7 +94,7 @@ void NetworkStateEndToEndTest::VerifyNewVideoSendStreamsRespectNetworkState( SendTask(task_queue(), [this, network_to_bring_up, &encoder_factory, transport]() { - CreateSenderCall(CallConfig(send_event_log_.get())); + CreateSenderCall(); sender_call_->SignalChannelNetworkState(network_to_bring_up, kNetworkUp); CreateSendConfig(1, 0, 0, transport); diff --git a/video/end_to_end_tests/stats_tests.cc b/video/end_to_end_tests/stats_tests.cc index cc0b328b2b..d6820eeac2 100644 --- a/video/end_to_end_tests/stats_tests.cc +++ b/video/end_to_end_tests/stats_tests.cc @@ -518,9 +518,9 @@ TEST_F(StatsEndToEndTest, MAYBE_ContentTypeSwitches) { metrics::Reset(); - CallConfig send_config(send_event_log_.get()); + CallConfig send_config = SendCallConfig(); test.ModifySenderBitrateConfig(&send_config.bitrate_config); - CallConfig recv_config(recv_event_log_.get()); + CallConfig recv_config = RecvCallConfig(); test.ModifyReceiverBitrateConfig(&recv_config.bitrate_config); VideoEncoderConfig encoder_config_with_screenshare; @@ -732,13 +732,13 @@ TEST_F(StatsEndToEndTest, CallReportsRttForSender) { Start(); }); - int64_t start_time_ms = clock_->TimeInMilliseconds(); + int64_t start_time_ms = env().clock().TimeInMilliseconds(); while (true) { Call::Stats stats; SendTask(task_queue(), [this, &stats]() { stats = sender_call_->GetStats(); }); ASSERT_GE(start_time_ms + test::VideoTestConstants::kDefaultTimeout.ms(), - clock_->TimeInMilliseconds()) + env().clock().TimeInMilliseconds()) << "No RTT stats before timeout!"; if (stats.rtt_ms != -1) { // To avoid failures caused by rounding or minor ntp clock adjustments, diff --git a/video/video_quality_test.cc b/video/video_quality_test.cc index 971c129329..99b722322a 100644 --- a/video/video_quality_test.cc +++ b/video/video_quality_test.cc @@ -375,7 +375,6 @@ VideoQualityTest::VideoQualityTest( std::unique_ptr injection_components) : clock_(Clock::GetRealTimeClock()), task_queue_factory_(CreateDefaultTaskQueueFactory()), - rtc_event_log_factory_(task_queue_factory_.get()), video_decoder_factory_([this](const SdpVideoFormat& format) { return this->CreateVideoDecoder(format); }), @@ -1221,10 +1220,10 @@ void VideoQualityTest::RunWithAnalyzer(const Params& params) { } if (!params.logging.rtc_event_log_name.empty()) { - send_event_log_ = rtc_event_log_factory_.CreateRtcEventLog( - RtcEventLog::EncodingType::NewFormat); - recv_event_log_ = rtc_event_log_factory_.CreateRtcEventLog( - RtcEventLog::EncodingType::NewFormat); + std::unique_ptr send_event_log = + rtc_event_log_factory_.Create(env()); + std::unique_ptr recv_event_log = + rtc_event_log_factory_.Create(env()); std::unique_ptr send_output( std::make_unique( params.logging.rtc_event_log_name + "_send", @@ -1234,19 +1233,18 @@ void VideoQualityTest::RunWithAnalyzer(const Params& params) { params.logging.rtc_event_log_name + "_recv", RtcEventLog::kUnlimitedOutput)); bool event_log_started = - send_event_log_->StartLogging(std::move(send_output), - RtcEventLog::kImmediateOutput) && - recv_event_log_->StartLogging(std::move(recv_output), - RtcEventLog::kImmediateOutput); + send_event_log->StartLogging(std::move(send_output), + RtcEventLog::kImmediateOutput) && + recv_event_log->StartLogging(std::move(recv_output), + RtcEventLog::kImmediateOutput); RTC_DCHECK(event_log_started); - } else { - send_event_log_ = std::make_unique(); - recv_event_log_ = std::make_unique(); + SetSendEventLog(std::move(send_event_log)); + SetRecvEventLog(std::move(recv_event_log)); } SendTask(task_queue(), [this, ¶ms, &send_transport, &recv_transport]() { - CallConfig send_call_config(send_event_log_.get()); - CallConfig recv_call_config(recv_event_log_.get()); + CallConfig send_call_config = SendCallConfig(); + CallConfig recv_call_config = RecvCallConfig(); send_call_config.bitrate_config = params.call.call_bitrate_config; recv_call_config.bitrate_config = params.call.call_bitrate_config; if (params_.audio.enabled) @@ -1444,10 +1442,10 @@ void VideoQualityTest::RunWithRenderers(const Params& params) { std::vector> loopback_renderers; if (!params.logging.rtc_event_log_name.empty()) { - send_event_log_ = rtc_event_log_factory_.CreateRtcEventLog( - RtcEventLog::EncodingType::NewFormat); - recv_event_log_ = rtc_event_log_factory_.CreateRtcEventLog( - RtcEventLog::EncodingType::NewFormat); + std::unique_ptr send_event_log = + rtc_event_log_factory_.Create(env()); + std::unique_ptr recv_event_log = + rtc_event_log_factory_.Create(env()); std::unique_ptr send_output( std::make_unique( params.logging.rtc_event_log_name + "_send", @@ -1457,14 +1455,13 @@ void VideoQualityTest::RunWithRenderers(const Params& params) { params.logging.rtc_event_log_name + "_recv", RtcEventLog::kUnlimitedOutput)); bool event_log_started = - send_event_log_->StartLogging(std::move(send_output), - /*output_period_ms=*/5000) && - recv_event_log_->StartLogging(std::move(recv_output), - /*output_period_ms=*/5000); + send_event_log->StartLogging(std::move(send_output), + /*output_period_ms=*/5000) && + recv_event_log->StartLogging(std::move(recv_output), + /*output_period_ms=*/5000); RTC_DCHECK(event_log_started); - } else { - send_event_log_ = std::make_unique(); - recv_event_log_ = std::make_unique(); + SetSendEventLog(std::move(send_event_log)); + SetRecvEventLog(std::move(recv_event_log)); } SendTask(task_queue(), [&]() { @@ -1473,9 +1470,9 @@ void VideoQualityTest::RunWithRenderers(const Params& params) { // TODO(ivica): Remove bitrate_config and use the default CallConfig(), to // match the full stack tests. - CallConfig send_call_config(send_event_log_.get()); + CallConfig send_call_config = SendCallConfig(); send_call_config.bitrate_config = params_.call.call_bitrate_config; - CallConfig recv_call_config(recv_event_log_.get()); + CallConfig recv_call_config = RecvCallConfig(); if (params_.audio.enabled) InitializeAudioDevice(&send_call_config, &recv_call_config,