Fix video_tests for force-test-env Use CreateTestEnvironment in video_tests to allow running with --force-test-environment. Bug: webrtc:521534686 Change-Id: I9b95514e2dac80a9e343e88c5520d24028edea8c Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/481860 Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#47993}
diff --git a/video/BUILD.gn b/video/BUILD.gn index 33bd20d..45979a5 100644 --- a/video/BUILD.gn +++ b/video/BUILD.gn
@@ -922,6 +922,7 @@ "../api/environment:environment_factory", "../api/video:video_frame_type", "../system_wrappers", + "../test:create_test_environment", "../test:test_support", "//call", "//call:call_interfaces", @@ -953,6 +954,7 @@ "../rtc_base:task_queue_for_test", "../rtc_base:threading", "../rtc_base/synchronization:mutex", + "../test:create_test_environment", "../test:fake_video_codecs", "../test:rtp_test_utils", "../test:test_common", @@ -1826,6 +1828,7 @@ "../modules/video_coding:nack_requester", "../rtc_base:logging", "../system_wrappers", + "../test:create_test_environment", "../test:create_test_field_trials", "../test:fake_encoded_frame", "../test:fake_video_codecs", @@ -1958,6 +1961,7 @@ "../rtc_base:unique_id_generator", "../rtc_base/experiments:alr_experiment", "../rtc_base/synchronization:mutex", + "../test:create_test_environment", "../test:create_test_field_trials", "../test:encoder_settings", "../test:fake_video_codecs", @@ -2090,6 +2094,7 @@ "../rtc_base/synchronization:mutex", "../system_wrappers", "../system_wrappers:metrics", + "../test:create_test_environment", "../test:create_test_field_trials", "../test:encoder_settings", "../test:fake_video_codecs", @@ -2133,6 +2138,7 @@ "../modules/video_coding:webrtc_vp8", "../rtc_base:task_queue_for_test", "../rtc_base:threading", + "../test:create_test_environment", "../test:direct_transport", "../test:encoder_settings", "../test:frame_generator_capturer",
diff --git a/video/corruption_detection/evaluation/BUILD.gn b/video/corruption_detection/evaluation/BUILD.gn index 0bdfa35..90b1106 100644 --- a/video/corruption_detection/evaluation/BUILD.gn +++ b/video/corruption_detection/evaluation/BUILD.gn
@@ -159,6 +159,7 @@ "../../../rtc_base:logging", "../../../rtc_base:macromagic", "../../../rtc_base/system:no_unique_address", + "../../../test:create_test_environment", "../../../test:fileutils", "../../../test:test_support", "../../../test:video_test_support", @@ -240,6 +241,7 @@ "../../../modules/video_coding/svc:svc_rate_allocator", "../../../rtc_base:checks", "../../../test:create_test_environment", + "../../../test:create_test_field_trials", "../../../test:fileutils", "../../../test:test_support", "../../../video/corruption_detection/evaluation:test_clip",
diff --git a/video/corruption_detection/evaluation/webrtc_picture_pair_provider.cc b/video/corruption_detection/evaluation/webrtc_picture_pair_provider.cc index 324bf8c..ae8c785 100644 --- a/video/corruption_detection/evaluation/webrtc_picture_pair_provider.cc +++ b/video/corruption_detection/evaluation/webrtc_picture_pair_provider.cc
@@ -17,7 +17,7 @@ #include <utility> #include <vector> -#include "api/environment/environment_factory.h" +#include "api/environment/environment.h" #include "api/scoped_refptr.h" #include "api/sequence_checker.h" #include "api/units/data_rate.h" @@ -39,6 +39,7 @@ #include "modules/video_coding/utility/simulcast_utility.h" #include "rtc_base/checks.h" #include "rtc_base/logging.h" +#include "test/create_test_environment.h" #include "test/gtest.h" #include "test/testsupport/file_utils.h" #include "test/testsupport/frame_reader.h" @@ -63,7 +64,18 @@ VideoCodecType type, std::unique_ptr<VideoEncoderFactory> encoder_factory, std::unique_ptr<VideoDecoderFactory> decoder_factory) - : env_(CreateEnvironment()), + : WebRtcEncoderDecoderPicturePairProvider(CreateTestEnvironment(), + type, + std::move(encoder_factory), + std::move(decoder_factory)) {} + +WebRtcEncoderDecoderPicturePairProvider:: + WebRtcEncoderDecoderPicturePairProvider( + const Environment& env, + VideoCodecType type, + std::unique_ptr<VideoEncoderFactory> encoder_factory, + std::unique_ptr<VideoDecoderFactory> decoder_factory) + : env_(env), type_(type), encoder_factory_(std::move(encoder_factory)), encoder_(encoder_factory_->Create(env_, GetSdpVideoFormat(type))),
diff --git a/video/corruption_detection/evaluation/webrtc_picture_pair_provider.h b/video/corruption_detection/evaluation/webrtc_picture_pair_provider.h index a3c39ae..ae53246 100644 --- a/video/corruption_detection/evaluation/webrtc_picture_pair_provider.h +++ b/video/corruption_detection/evaluation/webrtc_picture_pair_provider.h
@@ -48,6 +48,13 @@ public DecodedImageCallback { public: WebRtcEncoderDecoderPicturePairProvider( + const Environment& env, + VideoCodecType type, + std::unique_ptr<VideoEncoderFactory> encoder_factory, + std::unique_ptr<VideoDecoderFactory> decoder_factory); + + // Needed for downstream usage that does not construct Environment. + WebRtcEncoderDecoderPicturePairProvider( VideoCodecType type, std::unique_ptr<VideoEncoderFactory> encoder_factory, std::unique_ptr<VideoDecoderFactory> decoder_factory);
diff --git a/video/corruption_detection/evaluation/webrtc_picture_pair_provider_unittest.cc b/video/corruption_detection/evaluation/webrtc_picture_pair_provider_unittest.cc index aa405d9..76f4c93 100644 --- a/video/corruption_detection/evaluation/webrtc_picture_pair_provider_unittest.cc +++ b/video/corruption_detection/evaluation/webrtc_picture_pair_provider_unittest.cc
@@ -21,7 +21,6 @@ #include <vector> #include "absl/strings/string_view.h" -#include "api/field_trials.h" #include "api/scoped_refptr.h" #include "api/test/mock_video_decoder.h" #include "api/test/mock_video_decoder_factory.h" @@ -50,6 +49,7 @@ #include "modules/video_coding/utility/simulcast_rate_allocator.h" #include "rtc_base/checks.h" #include "test/create_test_environment.h" +#include "test/create_test_field_trials.h" #include "test/gmock.h" #include "test/gtest.h" #include "video/corruption_detection/evaluation/picture_pair_provider.h" @@ -175,7 +175,7 @@ void CreatePicturePairProvider(VideoCodecType codec_type) { picture_pair_provider_ = std::make_unique<WebRtcEncoderDecoderPicturePairProvider>( - codec_type, std::move(encoder_factory_), + CreateTestEnvironment(), codec_type, std::move(encoder_factory_), std::move(decoder_factory_)); } @@ -380,7 +380,7 @@ codec_config.spatialLayers[0].maxBitrate = bitrate_kbps; codec_config.spatialLayers[0].active = true; - SvcRateAllocator svc_rate_allocator(codec_config, FieldTrials("")); + SvcRateAllocator svc_rate_allocator(codec_config, CreateTestFieldTrials("")); VideoEncoder::RateControlParameters rate_params = VideoEncoder::RateControlParameters( svc_rate_allocator.GetAllocation(kDefaultBitrate.bps(), kFramerate), @@ -593,12 +593,12 @@ std::unique_ptr<WebRtcEncoderDecoderPicturePairProvider> webrtc_provider; if (codec_type_ != VideoCodecType::kVideoCodecAV1) { webrtc_provider = std::make_unique<WebRtcEncoderDecoderPicturePairProvider>( - codec_type_, CreateBuiltinVideoEncoderFactory(), - CreateBuiltinVideoDecoderFactory()); + CreateTestEnvironment(), codec_type_, + CreateBuiltinVideoEncoderFactory(), CreateBuiltinVideoDecoderFactory()); } else { // AV1 is injectible webrtc_provider = std::make_unique<WebRtcEncoderDecoderPicturePairProvider>( - codec_type_, + CreateTestEnvironment(), codec_type_, std::make_unique< VideoEncoderFactoryTemplate<LibaomAv1EncoderTemplateAdapter>>(), std::make_unique< @@ -633,12 +633,12 @@ std::unique_ptr<WebRtcEncoderDecoderPicturePairProvider> webrtc_provider; if (codec_type_ != VideoCodecType::kVideoCodecAV1) { webrtc_provider = std::make_unique<WebRtcEncoderDecoderPicturePairProvider>( - codec_type_, CreateBuiltinVideoEncoderFactory(), - CreateBuiltinVideoDecoderFactory()); + CreateTestEnvironment(), codec_type_, + CreateBuiltinVideoEncoderFactory(), CreateBuiltinVideoDecoderFactory()); } else { // AV1 is injectible webrtc_provider = std::make_unique<WebRtcEncoderDecoderPicturePairProvider>( - codec_type_, + CreateTestEnvironment(), codec_type_, std::make_unique< VideoEncoderFactoryTemplate<LibaomAv1EncoderTemplateAdapter>>(), std::make_unique< @@ -672,12 +672,12 @@ std::unique_ptr<WebRtcEncoderDecoderPicturePairProvider> webrtc_provider; if (codec_type_ != VideoCodecType::kVideoCodecAV1) { webrtc_provider = std::make_unique<WebRtcEncoderDecoderPicturePairProvider>( - codec_type_, CreateBuiltinVideoEncoderFactory(), - CreateBuiltinVideoDecoderFactory()); + CreateTestEnvironment(), codec_type_, + CreateBuiltinVideoEncoderFactory(), CreateBuiltinVideoDecoderFactory()); } else { // AV1 is injectible webrtc_provider = std::make_unique<WebRtcEncoderDecoderPicturePairProvider>( - codec_type_, + CreateTestEnvironment(), codec_type_, std::make_unique< VideoEncoderFactoryTemplate<LibaomAv1EncoderTemplateAdapter>>(), std::make_unique<
diff --git a/video/encoder_rtcp_feedback_unittest.cc b/video/encoder_rtcp_feedback_unittest.cc index c2ff402..9a3454b 100644 --- a/video/encoder_rtcp_feedback_unittest.cc +++ b/video/encoder_rtcp_feedback_unittest.cc
@@ -13,9 +13,9 @@ #include <cstdint> #include <vector> -#include "api/environment/environment_factory.h" #include "api/video/video_frame_type.h" #include "system_wrappers/include/clock.h" +#include "test/create_test_environment.h" #include "test/gmock.h" #include "test/gtest.h" #include "video/test/mock_video_stream_encoder.h" @@ -31,11 +31,12 @@ std::vector<uint32_t> ssrcs) : simulated_clock_(123456789), encoder_(), - encoder_rtcp_feedback_(CreateEnvironment(&simulated_clock_), - per_layer_pli_handling, - ssrcs, - &encoder_, - nullptr) {} + encoder_rtcp_feedback_( + CreateTestEnvironment({.time = &simulated_clock_}), + per_layer_pli_handling, + ssrcs, + &encoder_, + nullptr) {} protected: static const uint32_t kSsrc = 1234;
diff --git a/video/end_to_end_tests/bandwidth_tests.cc b/video/end_to_end_tests/bandwidth_tests.cc index bc27f9e..880ecdf 100644 --- a/video/end_to_end_tests/bandwidth_tests.cc +++ b/video/end_to_end_tests/bandwidth_tests.cc
@@ -14,7 +14,6 @@ #include <vector> #include "api/environment/environment.h" -#include "api/environment/environment_factory.h" #include "api/rtp_header_extension_id.h" #include "api/rtp_headers.h" #include "api/rtp_parameters.h" @@ -38,6 +37,7 @@ #include "rtc_base/thread.h" #include "rtc_base/thread_annotations.h" #include "test/call_test.h" +#include "test/create_test_environment.h" #include "test/fake_encoder.h" #include "test/gtest.h" #include "test/rtcp_packet_parser.h" @@ -208,7 +208,7 @@ explicit BweObserver(TaskQueueBase* task_queue) : EndToEndTest(test::VideoTestConstants::kDefaultTimeout), sender_call_(nullptr), - env_(CreateEnvironment()), + env_(CreateTestEnvironment()), sender_ssrc_(0), remb_bitrate_bps_(1000000), state_(kWaitForFirstRampUp),
diff --git a/video/end_to_end_tests/multi_stream_tester.cc b/video/end_to_end_tests/multi_stream_tester.cc index 75302a2..c3396e5 100644 --- a/video/end_to_end_tests/multi_stream_tester.cc +++ b/video/end_to_end_tests/multi_stream_tester.cc
@@ -18,7 +18,6 @@ #include <vector> #include "api/environment/environment.h" -#include "api/environment/environment_factory.h" #include "api/rtp_parameters.h" #include "api/test/create_frame_generator.h" #include "api/test/simulated_network.h" @@ -36,6 +35,7 @@ #include "modules/video_coding/codecs/vp8/include/vp8.h" #include "rtc_base/task_queue_for_test.h" #include "rtc_base/thread.h" +#include "test/create_test_environment.h" #include "test/direct_transport.h" #include "test/encoder_settings.h" #include "test/frame_generator_capturer.h" @@ -54,7 +54,7 @@ MultiStreamTester::~MultiStreamTester() = default; void MultiStreamTester::RunTest() { - Environment env = CreateEnvironment(); + Environment env = CreateTestEnvironment(); // Use high prioirity since this task_queue used for fake network delivering // at correct time. Those test tasks should be prefered over code under test // to make test more stable.
diff --git a/video/video_receive_stream2_unittest.cc b/video/video_receive_stream2_unittest.cc index 66c92f9..7acf33c 100644 --- a/video/video_receive_stream2_unittest.cc +++ b/video/video_receive_stream2_unittest.cc
@@ -22,7 +22,6 @@ #include "absl/memory/memory.h" #include "api/environment/environment.h" -#include "api/environment/environment_factory.h" #include "api/metronome/test/fake_metronome.h" #include "api/rtp_packet_info.h" #include "api/rtp_packet_infos.h" @@ -55,7 +54,7 @@ #include "modules/video_coding/nack_requester.h" #include "rtc_base/logging.h" #include "system_wrappers/include/clock.h" -#include "test/create_test_field_trials.h" +#include "test/create_test_environment.h" #include "test/fake_decoder.h" #include "test/fake_encoded_frame.h" #include "test/gmock.h" @@ -197,8 +196,7 @@ VideoReceiveStream2Test() : time_controller_(kStartTime), - env_(CreateEnvironment(time_controller_.CreateTaskQueueFactory(), - time_controller_.GetClock())), + env_(CreateTestEnvironment({.time = &time_controller_})), config_(&mock_transport_, &mock_decoder_factory_), call_stats_(&env_.clock(), time_controller_.GetMainThread()), fake_renderer_(&time_controller_), @@ -617,10 +615,10 @@ } TEST_P(VideoReceiveStream2Test, CalculateCorruptionScoreAsync) { - env_ = CreateEnvironment( - CreateTestFieldTrialsPtr("WebRTC-CorruptionDetectionFrameSelector/" - "asynchronous_evaluation:true/"), - time_controller_.CreateTaskQueueFactory(), time_controller_.GetClock()); + env_ = CreateTestEnvironment({.field_trials = + "WebRTC-CorruptionDetectionFrameSelector/" + "asynchronous_evaluation:true/", + .time = &time_controller_}); RecreateReceiveStream(); video_receive_stream_->Start(); @@ -654,10 +652,10 @@ TEST_P(VideoReceiveStream2Test, CalculateCorruptionScoreDropsFramesWhenQueueFull) { - env_ = CreateEnvironment( - CreateTestFieldTrialsPtr("WebRTC-CorruptionDetectionFrameSelector/" - "asynchronous_evaluation:true/"), - time_controller_.CreateTaskQueueFactory(), time_controller_.GetClock()); + env_ = CreateTestEnvironment({.field_trials = + "WebRTC-CorruptionDetectionFrameSelector/" + "asynchronous_evaluation:true/", + .time = &time_controller_}); RecreateReceiveStream(); video_receive_stream_->Start();
diff --git a/video/video_send_stream_tests.cc b/video/video_send_stream_tests.cc index 0562677..45b20f9 100644 --- a/video/video_send_stream_tests.cc +++ b/video/video_send_stream_tests.cc
@@ -25,7 +25,6 @@ #include "absl/strings/match.h" #include "absl/strings/string_view.h" #include "api/environment/environment.h" -#include "api/environment/environment_factory.h" #include "api/fec_controller_override.h" #include "api/field_trials.h" #include "api/field_trials_view.h" @@ -105,6 +104,7 @@ #include "rtc_base/unique_id_generator.h" #include "test/call_test.h" #include "test/configurable_frame_size_encoder.h" +#include "test/create_test_environment.h" #include "test/create_test_field_trials.h" #include "test/encoder_settings.h" #include "test/fake_encoder.h" @@ -1113,7 +1113,7 @@ EXPECT_TRUE(Wait()) << "Timed out while waiting for NACK retransmission."; } - const Environment env_ = CreateEnvironment(); + const Environment env_ = CreateTestEnvironment(); std::unique_ptr<internal::TransportAdapter> transport_adapter_; int retransmit_count_; const uint32_t media_ssrc_; @@ -1346,7 +1346,7 @@ EXPECT_TRUE(Wait()) << "Timed out while observing incoming RTP packets."; } - const Environment env_ = CreateEnvironment(); + const Environment env_ = CreateTestEnvironment(); std::unique_ptr<internal::TransportAdapter> transport_adapter_; test::ConfigurableFrameSizeEncoder encoder_; test::VideoEncoderProxyFactory encoder_factory_; @@ -1642,7 +1642,7 @@ } TaskQueueBase* const task_queue_; - const Environment env_ = CreateEnvironment(); + const Environment env_ = CreateTestEnvironment(); std::unique_ptr<ModuleRtpRtcpImpl2> rtp_rtcp_; std::unique_ptr<internal::TransportAdapter> feedback_transport_; RateLimiter retranmission_rate_limiter_;
diff --git a/video/video_stream_encoder_unittest.cc b/video/video_stream_encoder_unittest.cc index 38e22d9..ecbda56 100644 --- a/video/video_stream_encoder_unittest.cc +++ b/video/video_stream_encoder_unittest.cc
@@ -108,6 +108,7 @@ #include "rtc_base/time_utils.h" #include "system_wrappers/include/clock.h" #include "system_wrappers/include/metrics.h" +#include "test/create_test_environment.h" #include "test/create_test_field_trials.h" #include "test/encoder_settings.h" #include "test/fake_encoder.h" @@ -822,10 +823,8 @@ FieldTrials field_trials_ = CreateTestFieldTrials(); GlobalSimulatedTimeController time_controller_{Timestamp::Zero()}; - Environment env_ = - CreateEnvironment(&field_trials_, - time_controller_.GetClock(), - time_controller_.CreateTaskQueueFactory()); + Environment env_ = CreateTestEnvironment( + {.field_trials = &field_trials_, .time = &time_controller_}); std::unique_ptr<MockableSendStatisticsProxy> stats_proxy_ = std::make_unique<MockableSendStatisticsProxy>( time_controller_.GetClock(), @@ -1767,9 +1766,8 @@ protected: FieldTrials field_trials_ = CreateTestFieldTrials(); GlobalSimulatedTimeController time_controller_{Timestamp::Micros(1234)}; - Environment env_ = CreateEnvironment(&field_trials_, - time_controller_.GetClock(), - time_controller_.GetTaskQueueFactory()); + Environment env_ = CreateTestEnvironment( + {.field_trials = &field_trials_, .time = &time_controller_}); VideoSendStream::Config video_send_config_; VideoEncoderConfig video_encoder_config_; int codec_width_; @@ -10527,7 +10525,7 @@ // Lots of boiler plate. GlobalSimulatedTimeController time_controller(Timestamp::Zero()); - Environment env = CreateEnvironment(time_controller.GetClock()); + Environment env = CreateTestEnvironment({.time = &time_controller}); MockableSendStatisticsProxy stats_proxy( &env.clock(), VideoSendStream::Config(nullptr), VideoEncoderConfig::ContentType::kRealtimeVideo, env.field_trials());