Add VideoEncoderFactory::Create to pass Environment for VideoEncoder construction

Bug: webrtc:15860
Change-Id: I6197780aaaa9c29717cb94df5790645b674c3bc2
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/341900
Reviewed-by: Philip Eliasson <philipel@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41873}
diff --git a/api/video_codecs/video_encoder_factory.h b/api/video_codecs/video_encoder_factory.h
index d28a2a4..fa043f5 100644
--- a/api/video_codecs/video_encoder_factory.h
+++ b/api/video_codecs/video_encoder_factory.h
@@ -16,14 +16,15 @@
 #include <vector>
 
 #include "absl/types/optional.h"
+#include "api/environment/environment.h"
 #include "api/units/data_rate.h"
 #include "api/video/render_resolution.h"
 #include "api/video_codecs/sdp_video_format.h"
+#include "api/video_codecs/video_encoder.h"
+#include "rtc_base/checks.h"
 
 namespace webrtc {
 
-class VideoEncoder;
-
 // A factory that creates VideoEncoders.
 // NOTE: This class is still under development and may change without notice.
 class VideoEncoderFactory {
@@ -96,8 +97,21 @@
   }
 
   // Creates a VideoEncoder for the specified format.
+  virtual std::unique_ptr<VideoEncoder> Create(const Environment& env,
+                                               const SdpVideoFormat& format) {
+    return CreateVideoEncoder(format);
+  }
+
+  // Deprecated in favor of the `Create` above.
+  // TODO: bugs.webrtc.org/15860 - Make private when all callers are updated
+  // to use Create function above. Delete when all derived classes implement
+  // `Create` instead of this function.
   virtual std::unique_ptr<VideoEncoder> CreateVideoEncoder(
-      const SdpVideoFormat& format) = 0;
+      const SdpVideoFormat& format) {
+    // Newer code shouldn't call this function,
+    // Older code should implement it in derived classes.
+    RTC_CHECK_NOTREACHED();
+  }
 
   // This method creates a EncoderSelector to use for a VideoSendStream.
   // (and hence should probably been called CreateEncoderSelector()).
diff --git a/video/video_stream_encoder.cc b/video/video_stream_encoder.cc
index 35d9c43..c28d086 100644
--- a/video/video_stream_encoder.cc
+++ b/video/video_stream_encoder.cc
@@ -947,8 +947,7 @@
     encoder_.reset();
 
     encoder_ = MaybeCreateFrameDumpingEncoderWrapper(
-        settings_.encoder_factory->CreateVideoEncoder(
-            encoder_config_.video_format),
+        settings_.encoder_factory->Create(env_, encoder_config_.video_format),
         env_.field_trials());
     if (!encoder_) {
       RTC_LOG(LS_ERROR) << "CreateVideoEncoder failed, failing encoder format: "