Provide Environment when creating VideoEncoder in test code

Bug: webrtc:15860
Change-Id: I8c79ff58619716842e02f33e78a0529c631494e6
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/342280
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41884}
diff --git a/api/test/mock_video_encoder_factory.h b/api/test/mock_video_encoder_factory.h
index 02ee7aa..f9a393e 100644
--- a/api/test/mock_video_encoder_factory.h
+++ b/api/test/mock_video_encoder_factory.h
@@ -14,6 +14,7 @@
 #include <memory>
 #include <vector>
 
+#include "api/environment/environment.h"
 #include "api/video_codecs/sdp_video_format.h"
 #include "api/video_codecs/video_encoder.h"
 #include "api/video_codecs/video_encoder_factory.h"
@@ -30,6 +31,10 @@
               (),
               (const, override));
   MOCK_METHOD(std::unique_ptr<VideoEncoder>,
+              Create,
+              (const Environment&, const SdpVideoFormat&),
+              (override));
+  MOCK_METHOD(std::unique_ptr<VideoEncoder>,
               CreateVideoEncoder,
               (const SdpVideoFormat&),
               (override));
diff --git a/api/test/video/function_video_encoder_factory.h b/api/test/video/function_video_encoder_factory.h
index 98ece2b..8902c3e 100644
--- a/api/test/video/function_video_encoder_factory.h
+++ b/api/test/video/function_video_encoder_factory.h
@@ -16,6 +16,7 @@
 #include <utility>
 #include <vector>
 
+#include "api/environment/environment.h"
 #include "api/video_codecs/sdp_video_format.h"
 #include "api/video_codecs/video_encoder.h"
 #include "api/video_codecs/video_encoder_factory.h"
@@ -30,11 +31,13 @@
  public:
   explicit FunctionVideoEncoderFactory(
       std::function<std::unique_ptr<VideoEncoder>()> create)
-      : create_([create = std::move(create)](const SdpVideoFormat&) {
+      : create_([create = std::move(create)](const Environment&,
+                                             const SdpVideoFormat&) {
           return create();
         }) {}
   explicit FunctionVideoEncoderFactory(
-      std::function<std::unique_ptr<VideoEncoder>(const SdpVideoFormat&)>
+      std::function<std::unique_ptr<VideoEncoder>(const Environment&,
+                                                  const SdpVideoFormat&)>
           create)
       : create_(std::move(create)) {}
 
@@ -44,13 +47,14 @@
     return {};
   }
 
-  std::unique_ptr<VideoEncoder> CreateVideoEncoder(
-      const SdpVideoFormat& format) override {
-    return create_(format);
+  std::unique_ptr<VideoEncoder> Create(const Environment& env,
+                                       const SdpVideoFormat& format) override {
+    return create_(env, format);
   }
 
  private:
-  const std::function<std::unique_ptr<VideoEncoder>(const SdpVideoFormat&)>
+  const std::function<std::unique_ptr<VideoEncoder>(const Environment&,
+                                                    const SdpVideoFormat&)>
       create_;
 };
 
diff --git a/media/engine/webrtc_video_engine_unittest.cc b/media/engine/webrtc_video_engine_unittest.cc
index 02ba628..0e2548a 100644
--- a/media/engine/webrtc_video_engine_unittest.cc
+++ b/media/engine/webrtc_video_engine_unittest.cc
@@ -1415,7 +1415,7 @@
 
   // Mock encoder creation. `engine` take ownership of the encoder.
   const webrtc::SdpVideoFormat format("VP8");
-  EXPECT_CALL(*encoder_factory, CreateVideoEncoder(format)).WillOnce([&] {
+  EXPECT_CALL(*encoder_factory, Create(_, format)).WillOnce([&] {
     return std::make_unique<FakeWebRtcVideoEncoder>(nullptr);
   });
 
diff --git a/modules/video_coding/codecs/test/video_codec_test.cc b/modules/video_coding/codecs/test/video_codec_test.cc
index 0811685..b71e4e1 100644
--- a/modules/video_coding/codecs/test/video_codec_test.cc
+++ b/modules/video_coding/codecs/test/video_codec_test.cc
@@ -258,6 +258,7 @@
 }
 
 std::unique_ptr<VideoCodecStats> RunEncodeTest(
+    const Environment& env,
     std::string codec_type,
     std::string codec_impl,
     const VideoInfo& video_info,
@@ -292,7 +293,8 @@
     encoder_settings.encoder_output_base_path = output_path + "_enc_output";
   }
 
-  return VideoCodecTester::RunEncodeTest(source_settings, encoder_factory.get(),
+  return VideoCodecTester::RunEncodeTest(env, source_settings,
+                                         encoder_factory.get(),
                                          encoder_settings, encoding_settings);
 }
 
@@ -394,6 +396,7 @@
 
 TEST_P(BitrateAdaptationTest, BitrateAdaptation) {
   auto [codec_type, codec_impl, video_info, bitrate_kbps] = GetParam();
+  const Environment env = CreateEnvironment();
 
   int duration_s = 10;  // Duration of fixed rate interval.
   int num_frames =
@@ -417,7 +420,7 @@
   encoding_settings.merge(encoding_settings2);
 
   std::unique_ptr<VideoCodecStats> stats =
-      RunEncodeTest(codec_type, codec_impl, video_info, encoding_settings);
+      RunEncodeTest(env, codec_type, codec_impl, video_info, encoding_settings);
 
   VideoCodecStats::Stream stream;
   if (stats != nullptr) {
@@ -472,6 +475,7 @@
 
 TEST_P(FramerateAdaptationTest, FramerateAdaptation) {
   auto [codec_type, codec_impl, video_info, framerate_fps] = GetParam();
+  const Environment env = CreateEnvironment();
 
   int duration_s = 10;  // Duration of fixed rate interval.
 
@@ -497,7 +501,7 @@
   encoding_settings.merge(encoding_settings2);
 
   std::unique_ptr<VideoCodecStats> stats =
-      RunEncodeTest(codec_type, codec_impl, video_info, encoding_settings);
+      RunEncodeTest(env, codec_type, codec_impl, video_info, encoding_settings);
 
   VideoCodecStats::Stream stream;
   if (stats != nullptr) {
diff --git a/modules/video_coding/codecs/test/video_encoder_decoder_instantiation_tests.cc b/modules/video_coding/codecs/test/video_encoder_decoder_instantiation_tests.cc
index 5817507..fcc65e7 100644
--- a/modules/video_coding/codecs/test/video_encoder_decoder_instantiation_tests.cc
+++ b/modules/video_coding/codecs/test/video_encoder_decoder_instantiation_tests.cc
@@ -123,7 +123,7 @@
 TEST_P(VideoEncoderDecoderInstantiationTest, DISABLED_InstantiateVp8Codecs) {
   for (int i = 0; i < num_encoders_; ++i) {
     std::unique_ptr<VideoEncoder> encoder =
-        encoder_factory_->CreateVideoEncoder(vp8_format_);
+        encoder_factory_->Create(env_, vp8_format_);
     EXPECT_EQ(0, InitEncoder(kVideoCodecVP8, encoder.get()));
     encoders_.emplace_back(std::move(encoder));
   }
@@ -141,7 +141,7 @@
        DISABLED_InstantiateH264CBPCodecs) {
   for (int i = 0; i < num_encoders_; ++i) {
     std::unique_ptr<VideoEncoder> encoder =
-        encoder_factory_->CreateVideoEncoder(h264cbp_format_);
+        encoder_factory_->Create(env_, h264cbp_format_);
     EXPECT_EQ(0, InitEncoder(kVideoCodecH264, encoder.get()));
     encoders_.emplace_back(std::move(encoder));
   }
diff --git a/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc b/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc
index 508ac38..717e910 100644
--- a/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc
+++ b/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc
@@ -703,7 +703,7 @@
     decoder_format = *config_.decoder_format;
   }
 
-  encoder_ = encoder_factory_->CreateVideoEncoder(encoder_format);
+  encoder_ = encoder_factory_->Create(env, encoder_format);
   EXPECT_TRUE(encoder_) << "Encoder not successfully created.";
   if (encoder_ == nullptr) {
     return false;
diff --git a/modules/video_coding/utility/simulcast_test_fixture_impl.cc b/modules/video_coding/utility/simulcast_test_fixture_impl.cc
index ac076fd..3636366 100644
--- a/modules/video_coding/utility/simulcast_test_fixture_impl.cc
+++ b/modules/video_coding/utility/simulcast_test_fixture_impl.cc
@@ -261,7 +261,7 @@
     SdpVideoFormat video_format)
     : codec_type_(PayloadStringToCodecType(video_format.name)) {
   Environment env = CreateEnvironment();
-  encoder_ = encoder_factory->CreateVideoEncoder(video_format);
+  encoder_ = encoder_factory->Create(env, video_format);
   decoder_ = decoder_factory->Create(env, video_format);
   SetUpCodec((codec_type_ == kVideoCodecVP8 || codec_type_ == kVideoCodecH264)
                  ? kDefaultTemporalLayerProfile
diff --git a/rtc_tools/BUILD.gn b/rtc_tools/BUILD.gn
index 6637d14..4defa98 100644
--- a/rtc_tools/BUILD.gn
+++ b/rtc_tools/BUILD.gn
@@ -477,6 +477,8 @@
     deps = [
       "//api:create_frame_generator",
       "//api:frame_generator_api",
+      "//api/environment",
+      "//api/environment:environment_factory",
       "//api/video:builtin_video_bitrate_allocator_factory",
       "//api/video_codecs:builtin_video_encoder_factory",
       "//api/video_codecs:video_codecs_api",
diff --git a/rtc_tools/video_encoder/video_encoder.cc b/rtc_tools/video_encoder/video_encoder.cc
index 9436910..9ea8ee8 100644
--- a/rtc_tools/video_encoder/video_encoder.cc
+++ b/rtc_tools/video_encoder/video_encoder.cc
@@ -12,6 +12,8 @@
 #include "absl/flags/flag.h"
 #include "absl/flags/parse.h"
 #include "absl/flags/usage.h"
+#include "api/environment/environment.h"
+#include "api/environment/environment_factory.h"
 #include "api/test/create_frame_generator.h"
 #include "api/test/frame_generator_interface.h"
 #include "api/video/builtin_video_bitrate_allocator_factory.h"
@@ -308,6 +310,7 @@
   }
 
   std::unique_ptr<VideoEncoder> CreateAndInitializeVideoEncoder(
+      const Environment& env,
       const VideoCodec& video_codec_setting) {
     const std::string video_codec_string =
         CodecTypeToPayloadString(video_codec_setting.codecType);
@@ -316,8 +319,8 @@
 
     // Create video encoder.
     std::unique_ptr<VideoEncoder> video_encoder =
-        builtin_video_encoder_factory_->CreateVideoEncoder(
-            SdpVideoFormat(video_codec_string));
+        builtin_video_encoder_factory_->Create(
+            env, SdpVideoFormat(video_codec_string));
     RTC_CHECK(video_encoder);
 
     // Initialize video encoder.
@@ -408,6 +411,8 @@
   const uint32_t key_frame_interval = absl::GetFlag(FLAGS_key_frame_interval);
   const uint32_t maximum_number_of_frames = absl::GetFlag(FLAGS_frames);
 
+  const webrtc::Environment env = webrtc::CreateEnvironment();
+
   std::unique_ptr<webrtc::TestVideoEncoderFactoryWrapper>
       test_video_encoder_factory_wrapper =
           std::make_unique<webrtc::TestVideoEncoderFactoryWrapper>();
@@ -514,7 +519,7 @@
 
   std::unique_ptr<webrtc::VideoEncoder> video_encoder =
       test_video_encoder_factory_wrapper->CreateAndInitializeVideoEncoder(
-          video_codec_setting);
+          env, video_codec_setting);
   RTC_CHECK(video_encoder);
 
   // Create `TestEncodedImageCallback`.
diff --git a/test/BUILD.gn b/test/BUILD.gn
index d9f2b92..36ca545 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -1370,6 +1370,7 @@
   deps = [
     ":scoped_key_value_config",
     "../api:array_view",
+    "../api/environment",
     "../api/numerics:numerics",
     "../api/test/metrics:metric",
     "../api/test/metrics:metrics_logger",
diff --git a/test/pc/e2e/analyzer/video/BUILD.gn b/test/pc/e2e/analyzer/video/BUILD.gn
index 6adfc50..570e944 100644
--- a/test/pc/e2e/analyzer/video/BUILD.gn
+++ b/test/pc/e2e/analyzer/video/BUILD.gn
@@ -153,6 +153,7 @@
   deps = [
     ":encoded_image_data_injector_api",
     "../../../../../api:video_quality_analyzer_api",
+    "../../../../../api/environment",
     "../../../../../api/test/pclf:media_configuration",
     "../../../../../api/video:video_frame",
     "../../../../../api/video_codecs:video_codecs_api",
diff --git a/test/pc/e2e/analyzer/video/quality_analyzing_video_encoder.cc b/test/pc/e2e/analyzer/video/quality_analyzing_video_encoder.cc
index d7ef0b0..ef72dcf 100644
--- a/test/pc/e2e/analyzer/video/quality_analyzing_video_encoder.cc
+++ b/test/pc/e2e/analyzer/video/quality_analyzing_video_encoder.cc
@@ -15,6 +15,7 @@
 #include <utility>
 
 #include "absl/strings/string_view.h"
+#include "api/environment/environment.h"
 #include "api/video/video_codec_type.h"
 #include "api/video_codecs/video_encoder.h"
 #include "modules/video_coding/include/video_error_codes.h"
@@ -410,5 +411,13 @@
       stream_to_sfu_config_, injector_, analyzer_);
 }
 
+std::unique_ptr<VideoEncoder> QualityAnalyzingVideoEncoderFactory::Create(
+    const Environment& env,
+    const SdpVideoFormat& format) {
+  return std::make_unique<QualityAnalyzingVideoEncoder>(
+      peer_name_, delegate_->Create(env, format), bitrate_multiplier_,
+      stream_to_sfu_config_, injector_, analyzer_);
+}
+
 }  // namespace webrtc_pc_e2e
 }  // namespace webrtc
diff --git a/test/pc/e2e/analyzer/video/quality_analyzing_video_encoder.h b/test/pc/e2e/analyzer/video/quality_analyzing_video_encoder.h
index 4adeacc..338afaa 100644
--- a/test/pc/e2e/analyzer/video/quality_analyzing_video_encoder.h
+++ b/test/pc/e2e/analyzer/video/quality_analyzing_video_encoder.h
@@ -17,6 +17,7 @@
 #include <vector>
 
 #include "absl/strings/string_view.h"
+#include "api/environment/environment.h"
 #include "api/test/pclf/media_configuration.h"
 #include "api/test/video_quality_analyzer_interface.h"
 #include "api/video/video_frame.h"
@@ -178,6 +179,8 @@
       absl::optional<std::string> scalability_mode) const override;
   std::unique_ptr<VideoEncoder> CreateVideoEncoder(
       const SdpVideoFormat& format) override;
+  std::unique_ptr<VideoEncoder> Create(const Environment& env,
+                                       const SdpVideoFormat& format) override;
 
  private:
   const std::string peer_name_;
diff --git a/test/video_codec_tester.cc b/test/video_codec_tester.cc
index 1853af6..05c94ec 100644
--- a/test/video_codec_tester.cc
+++ b/test/video_codec_tester.cc
@@ -16,6 +16,7 @@
 #include <utility>
 
 #include "api/array_view.h"
+#include "api/environment/environment.h"
 #include "api/units/time_delta.h"
 #include "api/units/timestamp.h"
 #include "api/video/builtin_video_bitrate_allocator_factory.h"
@@ -883,10 +884,12 @@
   using EncodeCallback =
       absl::AnyInvocable<void(const EncodedImage& encoded_frame)>;
 
-  Encoder(VideoEncoderFactory* encoder_factory,
+  Encoder(const Environment& env,
+          VideoEncoderFactory* encoder_factory,
           const EncoderSettings& encoder_settings,
           VideoCodecAnalyzer* analyzer)
-      : encoder_factory_(encoder_factory),
+      : env_(env),
+        encoder_factory_(encoder_factory),
         analyzer_(analyzer),
         pacer_(encoder_settings.pacing_settings) {
     RTC_CHECK(analyzer_) << "Analyzer must be provided";
@@ -903,8 +906,8 @@
   }
 
   void Initialize(const EncodingSettings& encoding_settings) {
-    encoder_ = encoder_factory_->CreateVideoEncoder(
-        encoding_settings.sdp_video_format);
+    encoder_ =
+        encoder_factory_->Create(env_, encoding_settings.sdp_video_format);
     RTC_CHECK(encoder_) << "Could not create encoder for video format "
                         << encoding_settings.sdp_video_format.ToString();
 
@@ -1192,6 +1195,7 @@
     return encoded_frame;
   }
 
+  const Environment env_;
   VideoEncoderFactory* const encoder_factory_;
   std::unique_ptr<VideoEncoder> encoder_;
   VideoCodecAnalyzer* const analyzer_;
@@ -1552,6 +1556,7 @@
 
 std::unique_ptr<VideoCodecTester::VideoCodecStats>
 VideoCodecTester::RunEncodeTest(
+    const Environment& env,
     const VideoSourceSettings& source_settings,
     VideoEncoderFactory* encoder_factory,
     const EncoderSettings& encoder_settings,
@@ -1559,7 +1564,7 @@
   VideoSource video_source(source_settings);
   std::unique_ptr<VideoCodecAnalyzer> analyzer =
       std::make_unique<VideoCodecAnalyzer>(/*video_source=*/nullptr);
-  Encoder encoder(encoder_factory, encoder_settings, analyzer.get());
+  Encoder encoder(env, encoder_factory, encoder_settings, analyzer.get());
   encoder.Initialize(encoding_settings.begin()->second);
 
   for (const auto& [timestamp_rtp, frame_settings] : encoding_settings) {
@@ -1589,7 +1594,7 @@
   std::unique_ptr<VideoCodecAnalyzer> analyzer =
       std::make_unique<VideoCodecAnalyzer>(&video_source);
   const EncodingSettings& frame_settings = encoding_settings.begin()->second;
-  Encoder encoder(encoder_factory, encoder_settings, analyzer.get());
+  Encoder encoder(env, encoder_factory, encoder_settings, analyzer.get());
   encoder.Initialize(frame_settings);
 
   int num_spatial_layers =
diff --git a/test/video_codec_tester.h b/test/video_codec_tester.h
index 1db45d2..6733c86 100644
--- a/test/video_codec_tester.h
+++ b/test/video_codec_tester.h
@@ -18,6 +18,7 @@
 #include <vector>
 
 #include "absl/types/optional.h"
+#include "api/environment/environment.h"
 #include "api/numerics/samples_stats_counter.h"
 #include "api/test/metrics/metric.h"
 #include "api/test/metrics/metrics_logger.h"
@@ -207,6 +208,7 @@
 
   // Encodes video, collects and returns encode metrics.
   static std::unique_ptr<VideoCodecStats> RunEncodeTest(
+      const Environment& env,
       const VideoSourceSettings& source_settings,
       VideoEncoderFactory* encoder_factory,
       const EncoderSettings& encoder_settings,
diff --git a/test/video_codec_tester_unittest.cc b/test/video_codec_tester_unittest.cc
index 8ad6558..a5088ab 100644
--- a/test/video_codec_tester_unittest.cc
+++ b/test/video_codec_tester_unittest.cc
@@ -194,11 +194,10 @@
         .framerate = kTargetFramerate};
 
     NiceMock<MockVideoEncoderFactory> encoder_factory;
-    ON_CALL(encoder_factory, CreateVideoEncoder)
-        .WillByDefault([&](const SdpVideoFormat&) {
-          return std::make_unique<NiceMock<TestVideoEncoder>>(scalability_mode,
-                                                              encoded_frames);
-        });
+    ON_CALL(encoder_factory, Create).WillByDefault(WithoutArgs([&] {
+      return std::make_unique<NiceMock<TestVideoEncoder>>(scalability_mode,
+                                                          encoded_frames);
+    }));
 
     NiceMock<MockVideoDecoderFactory> decoder_factory;
     ON_CALL(decoder_factory, Create).WillByDefault(WithoutArgs([&] {
@@ -610,16 +609,16 @@
 
 TEST_P(VideoCodecTesterTestPacing, PaceEncode) {
   auto [pacing_settings, expected_delta_ms] = GetParam();
+  const Environment env = CreateEnvironment();
   VideoSourceSettings video_source{
       .file_path = source_yuv_file_path_,
       .resolution = {.width = kSourceWidth, .height = kSourceHeight},
       .framerate = kTargetFramerate};
 
   NiceMock<MockVideoEncoderFactory> encoder_factory;
-  ON_CALL(encoder_factory, CreateVideoEncoder(_))
-      .WillByDefault([](const SdpVideoFormat&) {
-        return std::make_unique<NiceMock<MockVideoEncoder>>();
-      });
+  ON_CALL(encoder_factory, Create).WillByDefault(WithoutArgs([] {
+    return std::make_unique<NiceMock<MockVideoEncoder>>();
+  }));
 
   std::map<uint32_t, EncodingSettings> encoding_settings =
       VideoCodecTester::CreateEncodingSettings(
@@ -629,7 +628,7 @@
   EncoderSettings encoder_settings;
   encoder_settings.pacing_settings = pacing_settings;
   std::vector<Frame> frames =
-      VideoCodecTester::RunEncodeTest(video_source, &encoder_factory,
+      VideoCodecTester::RunEncodeTest(env, video_source, &encoder_factory,
                                       encoder_settings, encoding_settings)
           ->Slice(/*filter=*/{}, /*merge=*/false);
   ASSERT_THAT(frames, SizeIs(kNumFrames));
diff --git a/video/end_to_end_tests/multi_codec_receive_tests.cc b/video/end_to_end_tests/multi_codec_receive_tests.cc
index 56fce60..4027b60 100644
--- a/video/end_to_end_tests/multi_codec_receive_tests.cc
+++ b/video/end_to_end_tests/multi_codec_receive_tests.cc
@@ -199,7 +199,8 @@
   EXPECT_TRUE(!configs.empty());
 
   test::FunctionVideoEncoderFactory encoder_factory(
-      [](const SdpVideoFormat& format) -> std::unique_ptr<VideoEncoder> {
+      [](const Environment& env,
+         const SdpVideoFormat& format) -> std::unique_ptr<VideoEncoder> {
         if (format.name == "VP8") {
           return VP8Encoder::Create();
         }
diff --git a/video/quality_scaling_tests.cc b/video/quality_scaling_tests.cc
index edd186d..26ef919 100644
--- a/video/quality_scaling_tests.cc
+++ b/video/quality_scaling_tests.cc
@@ -87,7 +87,8 @@
                   bool expect_scaling)
       : SendTest(expect_scaling ? kTimeout * 4 : kTimeout),
         encoder_factory_(
-            [](const SdpVideoFormat& format) -> std::unique_ptr<VideoEncoder> {
+            [](const Environment& env,
+               const SdpVideoFormat& format) -> std::unique_ptr<VideoEncoder> {
               if (format.name == "VP8")
                 return VP8Encoder::Create();
               if (format.name == "VP9")
diff --git a/video/video_quality_test.cc b/video/video_quality_test.cc
index 4e17b4e..551cd34 100644
--- a/video/video_quality_test.cc
+++ b/video/video_quality_test.cc
@@ -312,6 +312,7 @@
 }
 
 std::unique_ptr<VideoEncoder> VideoQualityTest::CreateVideoEncoder(
+    const Environment& env,
     const SdpVideoFormat& format,
     VideoAnalyzer* analyzer) {
   std::unique_ptr<VideoEncoder> encoder;
@@ -321,7 +322,7 @@
   } else if (format.name == "FakeCodec") {
     encoder = webrtc::FakeVideoEncoderFactory::CreateVideoEncoder();
   } else {
-    encoder = encoder_factory_->CreateVideoEncoder(format);
+    encoder = encoder_factory_->Create(env, format);
   }
 
   std::vector<FileWrapper> encoded_frame_dump_files;
@@ -372,12 +373,13 @@
           [this](const Environment& env, const SdpVideoFormat& format) {
             return this->CreateVideoDecoder(env, format);
           }),
-      video_encoder_factory_([this](const SdpVideoFormat& format) {
-        return this->CreateVideoEncoder(format, nullptr);
-      }),
+      video_encoder_factory_(
+          [this](const Environment& env, const SdpVideoFormat& format) {
+            return this->CreateVideoEncoder(env, format, nullptr);
+          }),
       video_encoder_factory_with_analyzer_(
-          [this](const SdpVideoFormat& format) {
-            return this->CreateVideoEncoder(format, analyzer_.get());
+          [this](const Environment& env, const SdpVideoFormat& format) {
+            return this->CreateVideoEncoder(env, format, analyzer_.get());
           }),
       video_bitrate_allocator_factory_(
           CreateBuiltinVideoBitrateAllocatorFactory()),
diff --git a/video/video_quality_test.h b/video/video_quality_test.h
index c5e63dd..508a7ac 100644
--- a/video/video_quality_test.h
+++ b/video/video_quality_test.h
@@ -82,7 +82,8 @@
   std::unique_ptr<VideoDecoder> CreateVideoDecoder(
       const Environment& env,
       const SdpVideoFormat& format);
-  std::unique_ptr<VideoEncoder> CreateVideoEncoder(const SdpVideoFormat& format,
+  std::unique_ptr<VideoEncoder> CreateVideoEncoder(const Environment& env,
+                                                   const SdpVideoFormat& format,
                                                    VideoAnalyzer* analyzer);
   void SetupVideo(Transport* send_transport, Transport* recv_transport);
   void SetupThumbnails(Transport* send_transport, Transport* recv_transport);