WebRTC-DeprecateGlobalFieldTrialString/Enabled/ - part 2

convert call/ (and the collaterals)

Bug: webrtc:10335
Change-Id: I8f6bc13c032713aa2a947724b464f6f35454d39a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/254320
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Jonas Oreland <jonaso@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36165}
diff --git a/call/BUILD.gn b/call/BUILD.gn
index b2b56b2..1bba3d7 100644
--- a/call/BUILD.gn
+++ b/call/BUILD.gn
@@ -178,11 +178,11 @@
     "../api:rtp_parameters",
     "../api:sequence_checker",
     "../api:transport_api",
+    "../api:webrtc_key_value_config",
     "../api/rtc_event_log",
     "../api/transport:field_trial_based_config",
     "../api/transport:goog_cc",
     "../api/transport:network_control",
-    "../api/transport:webrtc_key_value_config",
     "../api/units:data_rate",
     "../api/units:time_delta",
     "../api/units:timestamp",
@@ -291,6 +291,7 @@
     "../api:sequence_checker",
     "../api:simulated_network_api",
     "../api:transport_api",
+    "../api:webrtc_key_value_config",
     "../api/rtc_event_log",
     "../api/transport:network_control",
     "../api/units:time_delta",
@@ -491,6 +492,7 @@
         "../test:field_trial",
         "../test:mock_frame_transformer",
         "../test:mock_transport",
+        "../test:scoped_key_value_config",
         "../test:test_common",
         "../test:test_support",
         "../test:video_test_common",
diff --git a/call/adaptation/BUILD.gn b/call/adaptation/BUILD.gn
index 10a46a3..4661c3e 100644
--- a/call/adaptation/BUILD.gn
+++ b/call/adaptation/BUILD.gn
@@ -35,6 +35,7 @@
     "../../api:rtp_parameters",
     "../../api:scoped_refptr",
     "../../api:sequence_checker",
+    "../../api:webrtc_key_value_config",
     "../../api/adaptation:resource_adaptation_api",
     "../../api/task_queue:task_queue",
     "../../api/video:video_adaptation",
@@ -86,6 +87,7 @@
       "../../rtc_base/synchronization:mutex",
       "../../test:field_trial",
       "../../test:rtc_expect_death",
+      "../../test:scoped_key_value_config",
       "../../test:test_support",
     ]
     absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
diff --git a/call/adaptation/resource_adaptation_processor_unittest.cc b/call/adaptation/resource_adaptation_processor_unittest.cc
index 705223a..da2bc94 100644
--- a/call/adaptation/resource_adaptation_processor_unittest.cc
+++ b/call/adaptation/resource_adaptation_processor_unittest.cc
@@ -23,6 +23,7 @@
 #include "rtc_base/synchronization/mutex.h"
 #include "rtc_base/task_queue_for_test.h"
 #include "test/gtest.h"
+#include "test/scoped_key_value_config.h"
 
 namespace webrtc {
 
@@ -90,7 +91,8 @@
         other_resource_(FakeResource::Create("OtherFakeResource")),
         video_stream_adapter_(
             std::make_unique<VideoStreamAdapter>(&input_state_provider_,
-                                                 &frame_rate_provider_)),
+                                                 &frame_rate_provider_,
+                                                 field_trials_)),
         processor_(std::make_unique<ResourceAdaptationProcessor>(
             video_stream_adapter_.get())) {
     video_stream_adapter_->AddRestrictionsListener(&restrictions_listener_);
@@ -133,6 +135,7 @@
   }
 
  protected:
+  webrtc::test::ScopedKeyValueConfig field_trials_;
   FakeFrameRateProvider frame_rate_provider_;
   VideoStreamInputStateProvider input_state_provider_;
   rtc::scoped_refptr<FakeResource> resource_;
diff --git a/call/adaptation/video_stream_adapter.cc b/call/adaptation/video_stream_adapter.cc
index ce1c300..313bcc3 100644
--- a/call/adaptation/video_stream_adapter.cc
+++ b/call/adaptation/video_stream_adapter.cc
@@ -203,9 +203,11 @@
 
 VideoStreamAdapter::VideoStreamAdapter(
     VideoStreamInputStateProvider* input_state_provider,
-    VideoStreamEncoderObserver* encoder_stats_observer)
+    VideoStreamEncoderObserver* encoder_stats_observer,
+    const WebRtcKeyValueConfig& field_trials)
     : input_state_provider_(input_state_provider),
       encoder_stats_observer_(encoder_stats_observer),
+      balanced_settings_(field_trials),
       adaptation_validation_id_(0),
       degradation_preference_(DegradationPreference::DISABLED),
       awaiting_frame_size_change_(absl::nullopt) {
diff --git a/call/adaptation/video_stream_adapter.h b/call/adaptation/video_stream_adapter.h
index 7bf424a..a4a52f4 100644
--- a/call/adaptation/video_stream_adapter.h
+++ b/call/adaptation/video_stream_adapter.h
@@ -21,6 +21,7 @@
 #include "api/rtp_parameters.h"
 #include "api/video/video_adaptation_counters.h"
 #include "api/video/video_stream_encoder_observer.h"
+#include "api/webrtc_key_value_config.h"
 #include "call/adaptation/adaptation_constraint.h"
 #include "call/adaptation/degradation_preference_provider.h"
 #include "call/adaptation/video_source_restrictions.h"
@@ -123,7 +124,8 @@
 class VideoStreamAdapter {
  public:
   VideoStreamAdapter(VideoStreamInputStateProvider* input_state_provider,
-                     VideoStreamEncoderObserver* encoder_stats_observer);
+                     VideoStreamEncoderObserver* encoder_stats_observer,
+                     const WebRtcKeyValueConfig& field_trials);
   ~VideoStreamAdapter();
 
   VideoSourceRestrictions source_restrictions() const;
diff --git a/call/adaptation/video_stream_adapter_unittest.cc b/call/adaptation/video_stream_adapter_unittest.cc
index aba9cf1..8f29194 100644
--- a/call/adaptation/video_stream_adapter_unittest.cc
+++ b/call/adaptation/video_stream_adapter_unittest.cc
@@ -27,9 +27,9 @@
 #include "call/adaptation/video_source_restrictions.h"
 #include "call/adaptation/video_stream_input_state.h"
 #include "rtc_base/string_encode.h"
-#include "test/field_trial.h"
 #include "test/gmock.h"
 #include "test/gtest.h"
+#include "test/scoped_key_value_config.h"
 #include "test/testsupport/rtc_expect_death.h"
 
 namespace webrtc {
@@ -153,10 +153,12 @@
   VideoStreamAdapterTest()
       : field_trials_(BalancedFieldTrialConfig()),
         resource_(FakeResource::Create("FakeResource")),
-        adapter_(&input_state_provider_, &encoder_stats_observer_) {}
+        adapter_(&input_state_provider_,
+                 &encoder_stats_observer_,
+                 field_trials_) {}
 
  protected:
-  webrtc::test::ScopedFieldTrials field_trials_;
+  webrtc::test::ScopedKeyValueConfig field_trials_;
   FakeVideoStreamInputStateProvider input_state_provider_;
   rtc::scoped_refptr<Resource> resource_;
   testing::StrictMock<MockVideoStreamEncoderObserver> encoder_stats_observer_;
@@ -919,9 +921,11 @@
 
 TEST(VideoStreamAdapterDeathTest,
      SetDegradationPreferenceInvalidatesAdaptations) {
+  webrtc::test::ScopedKeyValueConfig field_trials;
   FakeVideoStreamInputStateProvider input_state_provider;
   testing::StrictMock<MockVideoStreamEncoderObserver> encoder_stats_observer_;
-  VideoStreamAdapter adapter(&input_state_provider, &encoder_stats_observer_);
+  VideoStreamAdapter adapter(&input_state_provider, &encoder_stats_observer_,
+                             field_trials);
   adapter.SetDegradationPreference(DegradationPreference::MAINTAIN_FRAMERATE);
   input_state_provider.SetInputState(1280 * 720, 30, kDefaultMinPixelsPerFrame);
   Adaptation adaptation = adapter.GetAdaptationDown();
@@ -930,9 +934,11 @@
 }
 
 TEST(VideoStreamAdapterDeathTest, AdaptDownInvalidatesAdaptations) {
+  webrtc::test::ScopedKeyValueConfig field_trials;
   FakeVideoStreamInputStateProvider input_state_provider;
   testing::StrictMock<MockVideoStreamEncoderObserver> encoder_stats_observer_;
-  VideoStreamAdapter adapter(&input_state_provider, &encoder_stats_observer_);
+  VideoStreamAdapter adapter(&input_state_provider, &encoder_stats_observer_,
+                             field_trials);
   adapter.SetDegradationPreference(DegradationPreference::MAINTAIN_RESOLUTION);
   input_state_provider.SetInputState(1280 * 720, 30, kDefaultMinPixelsPerFrame);
   Adaptation adaptation = adapter.GetAdaptationDown();
diff --git a/call/call.cc b/call/call.cc
index 2638b22..16f7b90 100644
--- a/call/call.cc
+++ b/call/call.cc
@@ -823,7 +823,8 @@
                        absl::bind_front(&PacketRouter::SendRemb,
                                         transport_send->packet_router()),
                        /*network_state_estimator=*/nullptr),
-      receive_time_calculator_(ReceiveTimeCalculator::CreateFromFieldTrial()),
+      receive_time_calculator_(
+          ReceiveTimeCalculator::CreateFromFieldTrial(*config.trials)),
       video_send_delay_stats_(new SendDelayStats(clock_)),
       start_of_call_(clock_->CurrentTime()),
       transport_send_ptr_(transport_send.get()),
@@ -1055,7 +1056,8 @@
       call_stats_->AsRtcpRttStats(), transport_send_.get(),
       bitrate_allocator_.get(), video_send_delay_stats_.get(), event_log_,
       std::move(config), std::move(encoder_config), suspended_video_send_ssrcs_,
-      suspended_video_payload_states_, std::move(fec_controller));
+      suspended_video_payload_states_, std::move(fec_controller),
+      *config_.trials);
 
   for (uint32_t ssrc : ssrcs) {
     RTC_DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end());
diff --git a/call/rampup_tests.cc b/call/rampup_tests.cc
index abd0f1f..999bb50 100644
--- a/call/rampup_tests.cc
+++ b/call/rampup_tests.cc
@@ -26,7 +26,6 @@
 #include "rtc_base/task_queue_for_test.h"
 #include "rtc_base/time_utils.h"
 #include "test/encoder_settings.h"
-#include "test/field_trial.h"
 #include "test/gtest.h"
 #include "test/testsupport/perf_test.h"
 
diff --git a/call/receive_time_calculator.cc b/call/receive_time_calculator.cc
index 94d1fd1..d6ffd39 100644
--- a/call/receive_time_calculator.cc
+++ b/call/receive_time_calculator.cc
@@ -16,22 +16,20 @@
 
 #include "rtc_base/experiments/field_trial_parser.h"
 #include "rtc_base/numerics/safe_minmax.h"
-#include "system_wrappers/include/field_trial.h"
 
 namespace webrtc {
 namespace {
-using ::webrtc::field_trial::IsEnabled;
 
 const char kBweReceiveTimeCorrection[] = "WebRTC-Bwe-ReceiveTimeFix";
 }  // namespace
 
-ReceiveTimeCalculatorConfig::ReceiveTimeCalculatorConfig()
+ReceiveTimeCalculatorConfig::ReceiveTimeCalculatorConfig(
+    const WebRtcKeyValueConfig& field_trials)
     : max_packet_time_repair("maxrep", TimeDelta::Millis(2000)),
       stall_threshold("stall", TimeDelta::Millis(5)),
       tolerance("tol", TimeDelta::Millis(1)),
       max_stall("maxstall", TimeDelta::Seconds(5)) {
-  std::string trial_string =
-      field_trial::FindFullName(kBweReceiveTimeCorrection);
+  std::string trial_string = field_trials.Lookup(kBweReceiveTimeCorrection);
   ParseFieldTrial(
       {&max_packet_time_repair, &stall_threshold, &tolerance, &max_stall},
       trial_string);
@@ -40,14 +38,16 @@
     const ReceiveTimeCalculatorConfig&) = default;
 ReceiveTimeCalculatorConfig::~ReceiveTimeCalculatorConfig() = default;
 
-ReceiveTimeCalculator::ReceiveTimeCalculator()
-    : config_(ReceiveTimeCalculatorConfig()) {}
+ReceiveTimeCalculator::ReceiveTimeCalculator(
+    const WebRtcKeyValueConfig& field_trials)
+    : config_(field_trials) {}
 
 std::unique_ptr<ReceiveTimeCalculator>
-ReceiveTimeCalculator::CreateFromFieldTrial() {
-  if (!IsEnabled(kBweReceiveTimeCorrection))
+ReceiveTimeCalculator::CreateFromFieldTrial(
+    const WebRtcKeyValueConfig& field_trials) {
+  if (!field_trials.IsEnabled(kBweReceiveTimeCorrection))
     return nullptr;
-  return std::make_unique<ReceiveTimeCalculator>();
+  return std::make_unique<ReceiveTimeCalculator>(field_trials);
 }
 
 int64_t ReceiveTimeCalculator::ReconcileReceiveTimes(int64_t packet_time_us,
diff --git a/call/receive_time_calculator.h b/call/receive_time_calculator.h
index 0bd3a82..276ddda 100644
--- a/call/receive_time_calculator.h
+++ b/call/receive_time_calculator.h
@@ -15,12 +15,14 @@
 #include <memory>
 
 #include "api/units/time_delta.h"
+#include "api/webrtc_key_value_config.h"
 #include "rtc_base/experiments/field_trial_parser.h"
 
 namespace webrtc {
 
 struct ReceiveTimeCalculatorConfig {
-  ReceiveTimeCalculatorConfig();
+  explicit ReceiveTimeCalculatorConfig(
+      const WebRtcKeyValueConfig& field_trials);
   ReceiveTimeCalculatorConfig(const ReceiveTimeCalculatorConfig&);
   ReceiveTimeCalculatorConfig& operator=(const ReceiveTimeCalculatorConfig&) =
       default;
@@ -41,8 +43,9 @@
 // is received.
 class ReceiveTimeCalculator {
  public:
-  static std::unique_ptr<ReceiveTimeCalculator> CreateFromFieldTrial();
-  ReceiveTimeCalculator();
+  static std::unique_ptr<ReceiveTimeCalculator> CreateFromFieldTrial(
+      const WebRtcKeyValueConfig& field_trials);
+  explicit ReceiveTimeCalculator(const WebRtcKeyValueConfig& field_trials);
   int64_t ReconcileReceiveTimes(int64_t packet_time_us_,
                                 int64_t system_time_us_,
                                 int64_t safe_time_us_);
diff --git a/call/receive_time_calculator_unittest.cc b/call/receive_time_calculator_unittest.cc
index d18fb1b..f2e3d54 100644
--- a/call/receive_time_calculator_unittest.cc
+++ b/call/receive_time_calculator_unittest.cc
@@ -21,6 +21,7 @@
 #include "rtc_base/random.h"
 #include "rtc_base/time_utils.h"
 #include "test/gtest.h"
+#include "test/scoped_key_value_config.h"
 
 namespace webrtc {
 namespace test {
@@ -168,6 +169,7 @@
 };
 
 TEST(ClockRepair, NoClockDrift) {
+  webrtc::test::ScopedKeyValueConfig field_trials;
   const int kSeeds = 10;
   const int kFirstSeed = 1;
   const int64_t kRuntimeUs = 10 * rtc::kNumMicrosecsPerSec;
@@ -177,7 +179,7 @@
     EmulatedMonotoneousClock monotone_clock(seed);
     EmulatedNonMonotoneousClock non_monotone_clock(
         seed + 1, kRuntimeUs + rtc::kNumMicrosecsPerSec, kDrift);
-    ReceiveTimeCalculator reception_time_tracker;
+    ReceiveTimeCalculator reception_time_tracker(field_trials);
     int64_t corrected_clock_0 = 0;
     int64_t reset_during_stall_tol_us = 0;
     bool initial_clock_stall = true;
diff --git a/call/rtp_payload_params.h b/call/rtp_payload_params.h
index 1f03fab..b1680a9 100644
--- a/call/rtp_payload_params.h
+++ b/call/rtp_payload_params.h
@@ -15,8 +15,8 @@
 #include <vector>
 
 #include "absl/types/optional.h"
-#include "api/transport/webrtc_key_value_config.h"
 #include "api/video_codecs/video_encoder.h"
+#include "api/webrtc_key_value_config.h"
 #include "call/rtp_config.h"
 #include "modules/rtp_rtcp/source/rtp_generic_frame_descriptor.h"
 #include "modules/rtp_rtcp/source/rtp_video_header.h"
diff --git a/call/rtp_payload_params_unittest.cc b/call/rtp_payload_params_unittest.cc
index 8b22716..b155c4c2 100644
--- a/call/rtp_payload_params_unittest.cc
+++ b/call/rtp_payload_params_unittest.cc
@@ -27,9 +27,9 @@
 #include "modules/video_coding/codecs/vp9/include/vp9_globals.h"
 #include "modules/video_coding/include/video_codec_interface.h"
 #include "test/explicit_key_value_config.h"
-#include "test/field_trial.h"
 #include "test/gmock.h"
 #include "test/gtest.h"
+#include "test/scoped_key_value_config.h"
 
 using ::testing::Each;
 using ::testing::ElementsAre;
@@ -275,8 +275,7 @@
 }
 
 TEST(RtpPayloadParamsTest, PictureIdForOldGenericFormat) {
-  test::ScopedFieldTrials generic_picture_id(
-      "WebRTC-GenericPictureId/Enabled/");
+  test::ScopedKeyValueConfig field_trials("WebRTC-GenericPictureId/Enabled/");
   RtpPayloadState state{};
 
   EncodedImage encoded_image;
@@ -284,7 +283,7 @@
   codec_info.codecType = kVideoCodecGeneric;
   encoded_image._frameType = VideoFrameType::kVideoFrameKey;
 
-  RtpPayloadParams params(kSsrc1, &state, FieldTrialBasedConfig());
+  RtpPayloadParams params(kSsrc1, &state, field_trials);
   RTPVideoHeader header =
       params.GetRtpVideoHeader(encoded_image, &codec_info, 10);
 
diff --git a/call/rtp_transport_controller_send.cc b/call/rtp_transport_controller_send.cc
index 230b048..f1a6201 100644
--- a/call/rtp_transport_controller_send.cc
+++ b/call/rtp_transport_controller_send.cc
@@ -134,7 +134,8 @@
       retransmission_rate_limiter_(clock, kRetransmitWindowSizeMs),
       task_queue_(task_queue_factory->CreateTaskQueue(
           "rtp_send_controller",
-          TaskQueueFactory::Priority::NORMAL)) {
+          TaskQueueFactory::Priority::NORMAL)),
+      field_trials_(*trials) {
   ParseFieldTrial({&relay_bandwidth_cap_},
                   trials->Lookup("WebRTC-Bwe-NetworkRouteConstraints"));
   initial_config_.constraints = ConvertConstraints(bitrate_config, clock_);
@@ -174,7 +175,8 @@
       // the parts of RtpTransportControllerSendInterface that are really used.
       this, event_log, &retransmission_rate_limiter_, std::move(fec_controller),
       frame_encryption_config.frame_encryptor,
-      frame_encryption_config.crypto_options, std::move(frame_transformer)));
+      frame_encryption_config.crypto_options, std::move(frame_transformer),
+      field_trials_));
   return video_rtp_senders_.back().get();
 }
 
diff --git a/call/rtp_transport_controller_send.h b/call/rtp_transport_controller_send.h
index e5ff162..e45ab21 100644
--- a/call/rtp_transport_controller_send.h
+++ b/call/rtp_transport_controller_send.h
@@ -218,6 +218,8 @@
   // `task_queue_` is defined last to ensure all pending tasks are cancelled
   // and deleted before any other members.
   rtc::TaskQueue task_queue_;
+
+  const WebRtcKeyValueConfig& field_trials_;
 };
 
 }  // namespace webrtc
diff --git a/call/rtp_video_sender.cc b/call/rtp_video_sender.cc
index 35e6bee..c5de3a7 100644
--- a/call/rtp_video_sender.cc
+++ b/call/rtp_video_sender.cc
@@ -358,8 +358,10 @@
     std::unique_ptr<FecController> fec_controller,
     FrameEncryptorInterface* frame_encryptor,
     const CryptoOptions& crypto_options,
-    rtc::scoped_refptr<FrameTransformerInterface> frame_transformer)
-    : send_side_bwe_with_overhead_(!absl::StartsWith(
+    rtc::scoped_refptr<FrameTransformerInterface> frame_transformer,
+    const WebRtcKeyValueConfig& field_trials)
+    : field_trials_(field_trials),
+      send_side_bwe_with_overhead_(!absl::StartsWith(
           field_trials_.Lookup("WebRTC-SendSideBwe-WithOverhead"),
           "Disabled")),
       use_frame_rate_for_overhead_(absl::StartsWith(
diff --git a/call/rtp_video_sender.h b/call/rtp_video_sender.h
index 7023804..1fa9a8b 100644
--- a/call/rtp_video_sender.h
+++ b/call/rtp_video_sender.h
@@ -23,8 +23,8 @@
 #include "api/fec_controller_override.h"
 #include "api/rtc_event_log/rtc_event_log.h"
 #include "api/sequence_checker.h"
-#include "api/transport/field_trial_based_config.h"
 #include "api/video_codecs/video_encoder.h"
+#include "api/webrtc_key_value_config.h"
 #include "call/rtp_config.h"
 #include "call/rtp_payload_params.h"
 #include "call/rtp_transport_controller_send_interface.h"
@@ -85,7 +85,8 @@
       std::unique_ptr<FecController> fec_controller,
       FrameEncryptorInterface* frame_encryptor,
       const CryptoOptions& crypto_options,  // move inside RtpTransport
-      rtc::scoped_refptr<FrameTransformerInterface> frame_transformer);
+      rtc::scoped_refptr<FrameTransformerInterface> frame_transformer,
+      const WebRtcKeyValueConfig& field_trials);
   ~RtpVideoSender() override;
 
   RtpVideoSender(const RtpVideoSender&) = delete;
@@ -166,7 +167,7 @@
                                  DataSize overhead_per_packet,
                                  Frequency framerate) const;
 
-  const FieldTrialBasedConfig field_trials_;
+  const WebRtcKeyValueConfig& field_trials_;
   const bool send_side_bwe_with_overhead_;
   const bool use_frame_rate_for_overhead_;
   const bool has_packet_feedback_;
diff --git a/call/rtp_video_sender_unittest.cc b/call/rtp_video_sender_unittest.cc
index c47717d..2f2ffb0 100644
--- a/call/rtp_video_sender_unittest.cc
+++ b/call/rtp_video_sender_unittest.cc
@@ -24,12 +24,12 @@
 #include "modules/video_coding/fec_controller_default.h"
 #include "modules/video_coding/include/video_codec_interface.h"
 #include "rtc_base/rate_limiter.h"
-#include "test/field_trial.h"
 #include "test/gmock.h"
 #include "test/gtest.h"
 #include "test/mock_frame_transformer.h"
 #include "test/mock_transport.h"
 #include "test/scenario/scenario.h"
+#include "test/scoped_key_value_config.h"
 #include "test/time_controller/simulated_time_controller.h"
 #include "video/send_delay_stats.h"
 #include "video/send_statistics_proxy.h"
@@ -118,7 +118,8 @@
       int payload_type,
       const std::map<uint32_t, RtpPayloadState>& suspended_payload_states,
       FrameCountObserver* frame_count_observer,
-      rtc::scoped_refptr<FrameTransformerInterface> frame_transformer)
+      rtc::scoped_refptr<FrameTransformerInterface> frame_transformer,
+      const WebRtcKeyValueConfig* field_trials = nullptr)
       : time_controller_(Timestamp::Millis(1000000)),
         config_(CreateVideoSendStreamConfig(&transport_,
                                             ssrcs,
@@ -134,7 +135,7 @@
             bitrate_config_,
             time_controller_.CreateProcessThread("PacerThread"),
             time_controller_.GetTaskQueueFactory(),
-            &field_trials_),
+            field_trials ? field_trials : &field_trials_),
         stats_proxy_(time_controller_.GetClock(),
                      config_,
                      VideoEncoderConfig::ContentType::kRealtimeVideo),
@@ -150,7 +151,8 @@
                         &stats_proxy_, &stats_proxy_, &send_delay_stats_),
         &transport_controller_, &event_log_, &retransmission_rate_limiter_,
         std::make_unique<FecControllerDefault>(time_controller_.GetClock()),
-        nullptr, CryptoOptions{}, frame_transformer);
+        nullptr, CryptoOptions{}, frame_transformer,
+        field_trials ? *field_trials : field_trials_);
   }
 
   RtpVideoSenderTestFixture(
@@ -158,25 +160,29 @@
       const std::vector<uint32_t>& rtx_ssrcs,
       int payload_type,
       const std::map<uint32_t, RtpPayloadState>& suspended_payload_states,
-      FrameCountObserver* frame_count_observer)
+      FrameCountObserver* frame_count_observer,
+      const WebRtcKeyValueConfig* field_trials = nullptr)
       : RtpVideoSenderTestFixture(ssrcs,
                                   rtx_ssrcs,
                                   payload_type,
                                   suspended_payload_states,
                                   frame_count_observer,
-                                  /*frame_transformer=*/nullptr) {}
+                                  /*frame_transformer=*/nullptr,
+                                  field_trials) {}
 
   RtpVideoSenderTestFixture(
       const std::vector<uint32_t>& ssrcs,
       const std::vector<uint32_t>& rtx_ssrcs,
       int payload_type,
-      const std::map<uint32_t, RtpPayloadState>& suspended_payload_states)
+      const std::map<uint32_t, RtpPayloadState>& suspended_payload_states,
+      const WebRtcKeyValueConfig* field_trials = nullptr)
       : RtpVideoSenderTestFixture(ssrcs,
                                   rtx_ssrcs,
                                   payload_type,
                                   suspended_payload_states,
                                   /*frame_count_observer=*/nullptr,
-                                  /*frame_transformer=*/nullptr) {}
+                                  /*frame_transformer=*/nullptr,
+                                  field_trials) {}
 
   ~RtpVideoSenderTestFixture() { SetActive(false); }
 
@@ -206,6 +212,7 @@
   }
 
  private:
+  test::ScopedKeyValueConfig field_trials_;
   NiceMock<MockTransport> transport_;
   NiceMock<MockRtcpIntraFrameObserver> encoder_feedback_;
   GlobalSimulatedTimeController time_controller_;
@@ -213,7 +220,6 @@
   VideoSendStream::Config config_;
   SendDelayStats send_delay_stats_;
   BitrateConstraints bitrate_config_;
-  const FieldTrialBasedConfig field_trials_;
   RtpTransportControllerSend transport_controller_;
   SendStatisticsProxy stats_proxy_;
   RateLimiter retransmission_rate_limiter_;
@@ -849,9 +855,9 @@
 }
 
 TEST(RtpVideoSenderTest, GenerateDependecyDescriptorForGenericCodecs) {
-  test::ScopedFieldTrials field_trials(
+  test::ScopedKeyValueConfig field_trials(
       "WebRTC-GenericCodecDependencyDescriptor/Enabled/");
-  RtpVideoSenderTestFixture test({kSsrc1}, {}, kPayloadType, {});
+  RtpVideoSenderTestFixture test({kSsrc1}, {}, kPayloadType, {}, &field_trials);
   test.SetActive(true);
 
   RtpHeaderExtensionMap extensions;
@@ -1031,7 +1037,7 @@
 }
 
 TEST(RtpVideoSenderTest, OverheadIsSubtractedFromTargetBitrate) {
-  test::ScopedFieldTrials field_trials(
+  test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-UseFrameRateForOverhead/Enabled/");
 
   // TODO(jakobi): RTP header size should not be hard coded.
@@ -1039,7 +1045,7 @@
   constexpr uint32_t kTransportPacketOverheadBytes = 40;
   constexpr uint32_t kOverheadPerPacketBytes =
       kRtpHeaderSizeBytes + kTransportPacketOverheadBytes;
-  RtpVideoSenderTestFixture test({kSsrc1}, {}, kPayloadType, {});
+  RtpVideoSenderTestFixture test({kSsrc1}, {}, kPayloadType, {}, &field_trials);
   test.router()->OnTransportOverheadChanged(kTransportPacketOverheadBytes);
   test.SetActive(true);
 
diff --git a/rtc_base/experiments/BUILD.gn b/rtc_base/experiments/BUILD.gn
index 56d5000..b9d24ca 100644
--- a/rtc_base/experiments/BUILD.gn
+++ b/rtc_base/experiments/BUILD.gn
@@ -126,6 +126,7 @@
   deps = [
     ":field_trial_parser",
     "../:rtc_base_approved",
+    "../../api:webrtc_key_value_config",
     "../../api/video_codecs:video_codecs_api",
     "../../system_wrappers:field_trial",
   ]
@@ -291,6 +292,7 @@
       "../../api/video_codecs:video_codecs_api",
       "../../system_wrappers:field_trial",
       "../../test:field_trial",
+      "../../test:scoped_key_value_config",
       "../../test:test_main",
       "../../test:test_support",
     ]
diff --git a/rtc_base/experiments/balanced_degradation_settings.cc b/rtc_base/experiments/balanced_degradation_settings.cc
index 90d44ef..7cd1a67 100644
--- a/rtc_base/experiments/balanced_degradation_settings.cc
+++ b/rtc_base/experiments/balanced_degradation_settings.cc
@@ -15,7 +15,6 @@
 #include "rtc_base/experiments/field_trial_list.h"
 #include "rtc_base/experiments/field_trial_parser.h"
 #include "rtc_base/logging.h"
-#include "system_wrappers/include/field_trial.h"
 
 namespace webrtc {
 namespace {
@@ -332,7 +331,8 @@
       av1(av1),
       generic(generic) {}
 
-BalancedDegradationSettings::BalancedDegradationSettings() {
+BalancedDegradationSettings::BalancedDegradationSettings(
+    const WebRtcKeyValueConfig& field_trials) {
   FieldTrialStructList<Config> configs(
       {FieldTrialStructMember("pixels", [](Config* c) { return &c->pixels; }),
        FieldTrialStructMember("fps", [](Config* c) { return &c->fps; }),
@@ -390,7 +390,7 @@
                               [](Config* c) { return &c->generic.kbps_res; })},
       {});
 
-  ParseFieldTrial({&configs}, field_trial::FindFullName(kFieldTrial));
+  ParseFieldTrial({&configs}, field_trials.Lookup(kFieldTrial));
 
   configs_ = GetValidOrDefault(configs.Get());
   RTC_DCHECK_GT(configs_.size(), 1);
diff --git a/rtc_base/experiments/balanced_degradation_settings.h b/rtc_base/experiments/balanced_degradation_settings.h
index 0b2f2f5..8255547 100644
--- a/rtc_base/experiments/balanced_degradation_settings.h
+++ b/rtc_base/experiments/balanced_degradation_settings.h
@@ -15,6 +15,7 @@
 
 #include "absl/types/optional.h"
 #include "api/video_codecs/video_encoder.h"
+#include "api/webrtc_key_value_config.h"
 
 namespace webrtc {
 
@@ -22,7 +23,7 @@
  public:
   static constexpr int kNoFpsDiff = -100;
 
-  BalancedDegradationSettings();
+  BalancedDegradationSettings(const WebRtcKeyValueConfig& field_trials);
   ~BalancedDegradationSettings();
 
   struct CodecTypeSpecific {
diff --git a/rtc_base/experiments/balanced_degradation_settings_unittest.cc b/rtc_base/experiments/balanced_degradation_settings_unittest.cc
index 92833ee..a32dbb4 100644
--- a/rtc_base/experiments/balanced_degradation_settings_unittest.cc
+++ b/rtc_base/experiments/balanced_degradation_settings_unittest.cc
@@ -13,8 +13,8 @@
 #include <limits>
 
 #include "rtc_base/gunit.h"
-#include "test/field_trial.h"
 #include "test/gmock.h"
+#include "test/scoped_key_value_config.h"
 
 namespace webrtc {
 namespace {
@@ -59,8 +59,8 @@
 }  // namespace
 
 TEST(BalancedDegradationSettings, GetsDefaultConfigIfNoList) {
-  webrtc::test::ScopedFieldTrials field_trials("");
-  BalancedDegradationSettings settings;
+  webrtc::test::ScopedKeyValueConfig field_trials("");
+  BalancedDegradationSettings settings(field_trials);
   VerifyIsDefault(settings.GetConfigs());
   EXPECT_TRUE(settings.CanAdaptUp(kVideoCodecVP8, 1, /*bitrate_bps*/ 1));
   EXPECT_TRUE(
@@ -75,10 +75,10 @@
 }
 
 TEST(BalancedDegradationSettings, GetsConfig) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:11|22|33,fps:5|15|25,other:4|5|6/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   EXPECT_THAT(settings.GetConfigs(),
               ::testing::ElementsAre(
                   BalancedDegradationSettings::Config{
@@ -117,35 +117,35 @@
 }
 
 TEST(BalancedDegradationSettings, GetsDefaultConfigForZeroFpsValue) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:0|15|25/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   VerifyIsDefault(settings.GetConfigs());
 }
 
 TEST(BalancedDegradationSettings, GetsDefaultConfigIfPixelsDecreases) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|999|3000,fps:5|15|25/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   VerifyIsDefault(settings.GetConfigs());
 }
 
 TEST(BalancedDegradationSettings, GetsDefaultConfigIfFramerateDecreases) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:5|4|25/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   VerifyIsDefault(settings.GetConfigs());
 }
 
 TEST(BalancedDegradationSettings, GetsConfigWithSpecificFps) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:5|15|25,vp8_fps:7|8|9,vp9_fps:9|10|11,"
       "h264_fps:11|12|13,av1_fps:1|2|3,generic_fps:13|14|15/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   EXPECT_THAT(settings.GetConfigs(),
               ::testing::ElementsAre(
                   BalancedDegradationSettings::Config{
@@ -184,34 +184,34 @@
 }
 
 TEST(BalancedDegradationSettings, GetsDefaultConfigForZeroVp8FpsValue) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:7|15|25,vp8_fps:0|15|25/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   VerifyIsDefault(settings.GetConfigs());
 }
 
 TEST(BalancedDegradationSettings, GetsDefaultConfigForInvalidFpsValue) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:7|15|25,vp8_fps:10|15|2000/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   VerifyIsDefault(settings.GetConfigs());
 }
 
 TEST(BalancedDegradationSettings, GetsDefaultConfigIfVp8FramerateDecreases) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:4|5|25,vp8_fps:5|4|25/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   VerifyIsDefault(settings.GetConfigs());
 }
 
 TEST(BalancedDegradationSettings, GetsMinFps) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:5|15|25/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   EXPECT_EQ(5, settings.MinFps(kVideoCodecVP8, 1));
   EXPECT_EQ(5, settings.MinFps(kVideoCodecVP8, 1000));
   EXPECT_EQ(15, settings.MinFps(kVideoCodecVP8, 1001));
@@ -223,10 +223,10 @@
 }
 
 TEST(BalancedDegradationSettings, GetsVp8MinFps) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:5|15|25,vp8_fps:7|10|12/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   EXPECT_EQ(7, settings.MinFps(kVideoCodecVP8, 1));
   EXPECT_EQ(7, settings.MinFps(kVideoCodecVP8, 1000));
   EXPECT_EQ(10, settings.MinFps(kVideoCodecVP8, 1001));
@@ -238,10 +238,10 @@
 }
 
 TEST(BalancedDegradationSettings, GetsMaxFps) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:5|15|25/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   EXPECT_EQ(15, settings.MaxFps(kVideoCodecVP8, 1));
   EXPECT_EQ(15, settings.MaxFps(kVideoCodecVP8, 1000));
   EXPECT_EQ(25, settings.MaxFps(kVideoCodecVP8, 1001));
@@ -251,10 +251,10 @@
 }
 
 TEST(BalancedDegradationSettings, GetsVp8MaxFps) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:5|15|25,vp8_fps:7|10|12/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   EXPECT_EQ(10, settings.MaxFps(kVideoCodecVP8, 1));
   EXPECT_EQ(10, settings.MaxFps(kVideoCodecVP8, 1000));
   EXPECT_EQ(12, settings.MaxFps(kVideoCodecVP8, 1001));
@@ -264,39 +264,39 @@
 }
 
 TEST(BalancedDegradationSettings, GetsVp9Fps) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:5|15|25,vp9_fps:7|10|12/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   EXPECT_EQ(7, settings.MinFps(kVideoCodecVP9, 1000));
   EXPECT_EQ(10, settings.MaxFps(kVideoCodecVP9, 1000));
 }
 
 TEST(BalancedDegradationSettings, GetsH264Fps) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:5|15|25,h264_fps:8|11|13/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   EXPECT_EQ(11, settings.MinFps(kVideoCodecH264, 2000));
   EXPECT_EQ(13, settings.MaxFps(kVideoCodecH264, 2000));
 }
 
 TEST(BalancedDegradationSettings, GetsGenericFps) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:5|15|25,generic_fps:9|12|14/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   EXPECT_EQ(14, settings.MinFps(kVideoCodecGeneric, 3000));
   EXPECT_EQ(std::numeric_limits<int>::max(),
             settings.MaxFps(kVideoCodecGeneric, 3000));
 }
 
 TEST(BalancedDegradationSettings, GetsUnlimitedForMaxValidFps) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:5|15|100,vp8_fps:30|100|100/");
   const int kUnlimitedFps = std::numeric_limits<int>::max();
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   EXPECT_EQ(15, settings.MinFps(kVideoCodecH264, 2000));
   EXPECT_EQ(kUnlimitedFps, settings.MinFps(kVideoCodecH264, 2001));
   EXPECT_EQ(30, settings.MinFps(kVideoCodecVP8, 1000));
@@ -304,7 +304,7 @@
 }
 
 TEST(BalancedDegradationSettings, GetsConfigWithBitrate) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:11|22|33,fps:5|15|25,kbps:44|88|99,kbps_res:55|111|222,"
       "vp8_kbps:11|12|13,vp8_kbps_res:14|15|16,"
@@ -312,7 +312,7 @@
       "h264_kbps:31|32|33,h264_kbps_res:34|35|36,"
       "av1_kbps:41|42|43,av1_kbps_res:44|45|46,"
       "generic_kbps:51|52|53,generic_kbps_res:54|55|56/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   EXPECT_THAT(settings.GetConfigs(),
               ::testing::ElementsAre(
                   BalancedDegradationSettings::Config{
@@ -351,29 +351,29 @@
 }
 
 TEST(BalancedDegradationSettings, GetsDefaultConfigIfBitrateDecreases) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:11|22|33,fps:5|15|25,kbps:44|43|99/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   VerifyIsDefault(settings.GetConfigs());
 }
 
 TEST(BalancedDegradationSettings,
      GetsDefaultConfigIfBitrateDecreasesWithUnsetValue) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:11|22|33,fps:5|15|25,kbps:44|0|43/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   VerifyIsDefault(settings.GetConfigs());
 }
 
 TEST(BalancedDegradationSettings, CanAdaptUp) {
   VideoCodecType vp8 = kVideoCodecVP8;
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000|4000,fps:5|15|25|30,kbps:0|80|0|90,"
       "vp9_kbps:40|50|60|70/");
-  BalancedDegradationSettings s;
+  BalancedDegradationSettings s(field_trials);
   EXPECT_TRUE(s.CanAdaptUp(vp8, 1000, 0));  // No bitrate provided.
   EXPECT_FALSE(s.CanAdaptUp(vp8, 1000, 79000));
   EXPECT_TRUE(s.CanAdaptUp(vp8, 1000, 80000));
@@ -384,12 +384,12 @@
 }
 
 TEST(BalancedDegradationSettings, CanAdaptUpWithCodecType) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000|4000,fps:5|15|25|30,vp8_kbps:0|30|40|50,"
       "vp9_kbps:0|60|70|80,h264_kbps:0|55|65|75,av1_kbps:0|77|88|99,"
       "generic_kbps:0|25|35|45/");
-  BalancedDegradationSettings s;
+  BalancedDegradationSettings s(field_trials);
   EXPECT_FALSE(s.CanAdaptUp(kVideoCodecVP8, 1000, 29000));
   EXPECT_TRUE(s.CanAdaptUp(kVideoCodecVP8, 1000, 30000));
   EXPECT_FALSE(s.CanAdaptUp(kVideoCodecVP9, 1000, 59000));
@@ -405,11 +405,11 @@
 
 TEST(BalancedDegradationSettings, CanAdaptUpResolution) {
   VideoCodecType vp8 = kVideoCodecVP8;
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000|4000,fps:5|15|25|30,kbps_res:0|80|0|90,"
       "vp9_kbps_res:40|50|60|70/");
-  BalancedDegradationSettings s;
+  BalancedDegradationSettings s(field_trials);
   EXPECT_TRUE(s.CanAdaptUpResolution(vp8, 1000, 0));  // No bitrate provided.
   EXPECT_FALSE(s.CanAdaptUpResolution(vp8, 1000, 79000));
   EXPECT_TRUE(s.CanAdaptUpResolution(vp8, 1000, 80000));
@@ -420,12 +420,12 @@
 }
 
 TEST(BalancedDegradationSettings, CanAdaptUpResolutionWithCodecType) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000|4000,fps:5|15|25|30,vp8_kbps_res:0|30|40|50,"
       "vp9_kbps_res:0|60|70|80,h264_kbps_res:0|55|65|75,"
       "av1_kbps_res:0|77|88|99,generic_kbps_res:0|25|35|45/");
-  BalancedDegradationSettings s;
+  BalancedDegradationSettings s(field_trials);
   EXPECT_FALSE(s.CanAdaptUpResolution(kVideoCodecVP8, 1000, 29000));
   EXPECT_TRUE(s.CanAdaptUpResolution(kVideoCodecVP8, 1000, 30000));
   EXPECT_FALSE(s.CanAdaptUpResolution(kVideoCodecVP9, 1000, 59000));
@@ -441,10 +441,10 @@
 }
 
 TEST(BalancedDegradationSettings, GetsFpsDiff) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:5|15|25,fps_diff:0|-2|3/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   EXPECT_EQ(0, settings.MinFpsDiff(1));
   EXPECT_EQ(0, settings.MinFpsDiff(1000));
   EXPECT_EQ(-2, settings.MinFpsDiff(1001));
@@ -455,21 +455,21 @@
 }
 
 TEST(BalancedDegradationSettings, GetsNoFpsDiffIfValueBelowMinSetting) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:5|15|25,fps_diff:-100|-99|-101/");
   // Min valid fps_diff setting: -99.
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   EXPECT_FALSE(settings.MinFpsDiff(1000));
   EXPECT_EQ(-99, settings.MinFpsDiff(2000));
   EXPECT_FALSE(settings.MinFpsDiff(3000));
 }
 
 TEST(BalancedDegradationSettings, QpThresholdsNotSetByDefault) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:5|15|25/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecVP8, 1));
   EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecVP9, 1));
   EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecH264, 1));
@@ -478,13 +478,13 @@
 }
 
 TEST(BalancedDegradationSettings, GetsConfigWithQpThresholds) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:5|15|25,vp8_qp_low:89|90|88,"
       "vp8_qp_high:90|91|92,vp9_qp_low:27|28|29,vp9_qp_high:120|130|140,"
       "h264_qp_low:12|13|14,h264_qp_high:20|30|40,av1_qp_low:2|3|4,"
       "av1_qp_high:11|33|44,generic_qp_low:7|6|5,generic_qp_high:22|23|24/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   EXPECT_THAT(settings.GetConfigs(),
               ::testing::ElementsAre(
                   BalancedDegradationSettings::Config{
@@ -523,54 +523,54 @@
 }
 
 TEST(BalancedDegradationSettings, GetsDefaultConfigIfOnlyHasLowThreshold) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:5|15|25,vp8_qp_low:89|90|88/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   VerifyIsDefault(settings.GetConfigs());
 }
 
 TEST(BalancedDegradationSettings, GetsDefaultConfigIfOnlyHasHighThreshold) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:5|15|25,vp8_qp_high:90|91|92/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   VerifyIsDefault(settings.GetConfigs());
 }
 
 TEST(BalancedDegradationSettings, GetsDefaultConfigIfLowEqualsHigh) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:5|15|25,"
       "vp8_qp_low:89|90|88,vp8_qp_high:90|91|88/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   VerifyIsDefault(settings.GetConfigs());
 }
 
 TEST(BalancedDegradationSettings, GetsDefaultConfigIfLowGreaterThanHigh) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:5|15|25,"
       "vp8_qp_low:89|90|88,vp8_qp_high:90|91|87/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   VerifyIsDefault(settings.GetConfigs());
 }
 
 TEST(BalancedDegradationSettings, GetsDefaultConfigForZeroQpValue) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:5|15|25,"
       "vp8_qp_low:89|0|88,vp8_qp_high:90|91|92/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   VerifyIsDefault(settings.GetConfigs());
 }
 
 TEST(BalancedDegradationSettings, GetsVp8QpThresholds) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:5|15|25,"
       "vp8_qp_low:89|90|88,vp8_qp_high:90|91|92/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   EXPECT_EQ(89, settings.GetQpThresholds(kVideoCodecVP8, 1)->low);
   EXPECT_EQ(90, settings.GetQpThresholds(kVideoCodecVP8, 1)->high);
   EXPECT_EQ(90, settings.GetQpThresholds(kVideoCodecVP8, 1000)->high);
@@ -582,11 +582,11 @@
 }
 
 TEST(BalancedDegradationSettings, GetsVp9QpThresholds) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:5|15|25,"
       "vp9_qp_low:55|56|57,vp9_qp_high:155|156|157/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   const auto thresholds = settings.GetQpThresholds(kVideoCodecVP9, 1000);
   EXPECT_TRUE(thresholds);
   EXPECT_EQ(55, thresholds->low);
@@ -594,11 +594,11 @@
 }
 
 TEST(BalancedDegradationSettings, GetsH264QpThresholds) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:5|15|25,"
       "h264_qp_low:21|22|23,h264_qp_high:41|43|42/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   const auto thresholds = settings.GetQpThresholds(kVideoCodecH264, 2000);
   EXPECT_TRUE(thresholds);
   EXPECT_EQ(22, thresholds->low);
@@ -606,11 +606,11 @@
 }
 
 TEST(BalancedDegradationSettings, GetsGenericQpThresholds) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:1000|2000|3000,fps:5|15|25,"
       "generic_qp_low:2|3|4,generic_qp_high:22|23|24/");
-  BalancedDegradationSettings settings;
+  BalancedDegradationSettings settings(field_trials);
   const auto thresholds = settings.GetQpThresholds(kVideoCodecGeneric, 3000);
   EXPECT_TRUE(thresholds);
   EXPECT_EQ(4, thresholds->low);
diff --git a/video/BUILD.gn b/video/BUILD.gn
index 81d511e..7e016af 100644
--- a/video/BUILD.gn
+++ b/video/BUILD.gn
@@ -67,6 +67,7 @@
     "../api:scoped_refptr",
     "../api:sequence_checker",
     "../api:transport_api",
+    "../api:webrtc_key_value_config",
     "../api/crypto:frame_decryptor_interface",
     "../api/crypto:options",
     "../api/rtc_event_log",
@@ -429,6 +430,7 @@
     ":frame_cadence_adapter",
     "../api:rtp_parameters",
     "../api:sequence_checker",
+    "../api:webrtc_key_value_config",
     "../api/adaptation:resource_adaptation_api",
     "../api/task_queue:task_queue",
     "../api/units:data_rate",
@@ -902,6 +904,7 @@
       "../test:null_transport",
       "../test:perf_test",
       "../test:rtp_test_utils",
+      "../test:scoped_key_value_config",
       "../test:test_common",
       "../test:test_support",
       "../test:video_test_common",
diff --git a/video/adaptation/BUILD.gn b/video/adaptation/BUILD.gn
index 11962c0..84e6a32 100644
--- a/video/adaptation/BUILD.gn
+++ b/video/adaptation/BUILD.gn
@@ -36,6 +36,7 @@
     "../../api:rtp_parameters",
     "../../api:scoped_refptr",
     "../../api:sequence_checker",
+    "../../api:webrtc_key_value_config",
     "../../api/adaptation:resource_adaptation_api",
     "../../api/task_queue:task_queue",
     "../../api/units:data_rate",
diff --git a/video/adaptation/balanced_constraint.cc b/video/adaptation/balanced_constraint.cc
index ec0b8e4..2a54840 100644
--- a/video/adaptation/balanced_constraint.cc
+++ b/video/adaptation/balanced_constraint.cc
@@ -19,8 +19,10 @@
 namespace webrtc {
 
 BalancedConstraint::BalancedConstraint(
-    DegradationPreferenceProvider* degradation_preference_provider)
+    DegradationPreferenceProvider* degradation_preference_provider,
+    const WebRtcKeyValueConfig& field_trials)
     : encoder_target_bitrate_bps_(absl::nullopt),
+      balanced_settings_(field_trials),
       degradation_preference_provider_(degradation_preference_provider) {
   RTC_DCHECK(degradation_preference_provider_);
   sequence_checker_.Detach();
diff --git a/video/adaptation/balanced_constraint.h b/video/adaptation/balanced_constraint.h
index 0bbd670..ba465ab 100644
--- a/video/adaptation/balanced_constraint.h
+++ b/video/adaptation/balanced_constraint.h
@@ -15,6 +15,7 @@
 
 #include "absl/types/optional.h"
 #include "api/sequence_checker.h"
+#include "api/webrtc_key_value_config.h"
 #include "call/adaptation/adaptation_constraint.h"
 #include "call/adaptation/degradation_preference_provider.h"
 #include "rtc_base/experiments/balanced_degradation_settings.h"
@@ -24,8 +25,9 @@
 
 class BalancedConstraint : public AdaptationConstraint {
  public:
-  explicit BalancedConstraint(
-      DegradationPreferenceProvider* degradation_preference_provider);
+  BalancedConstraint(
+      DegradationPreferenceProvider* degradation_preference_provider,
+      const WebRtcKeyValueConfig& field_trials);
   ~BalancedConstraint() override = default;
 
   void OnEncoderTargetBitrateUpdated(
diff --git a/video/adaptation/video_stream_encoder_resource_manager.cc b/video/adaptation/video_stream_encoder_resource_manager.cc
index 2847cdb..cb2ab14 100644
--- a/video/adaptation/video_stream_encoder_resource_manager.cc
+++ b/video/adaptation/video_stream_encoder_resource_manager.cc
@@ -266,11 +266,13 @@
     Clock* clock,
     bool experiment_cpu_load_estimator,
     std::unique_ptr<OveruseFrameDetector> overuse_detector,
-    DegradationPreferenceProvider* degradation_preference_provider)
+    DegradationPreferenceProvider* degradation_preference_provider,
+    const WebRtcKeyValueConfig& field_trials)
     : degradation_preference_provider_(degradation_preference_provider),
       bitrate_constraint_(std::make_unique<BitrateConstraint>()),
-      balanced_constraint_(std::make_unique<BalancedConstraint>(
-          degradation_preference_provider_)),
+      balanced_constraint_(
+          std::make_unique<BalancedConstraint>(degradation_preference_provider_,
+                                               field_trials)),
       encode_usage_resource_(
           EncodeUsageResource::Create(std::move(overuse_detector))),
       quality_scaler_resource_(QualityScalerResource::Create()),
@@ -283,6 +285,7 @@
       encoder_stats_observer_(encoder_stats_observer),
       degradation_preference_(DegradationPreference::DISABLED),
       video_source_restrictions_(),
+      balanced_settings_(field_trials),
       clock_(clock),
       experiment_cpu_load_estimator_(experiment_cpu_load_estimator),
       initial_frame_dropper_(
diff --git a/video/adaptation/video_stream_encoder_resource_manager.h b/video/adaptation/video_stream_encoder_resource_manager.h
index 26b8db3..223af4e 100644
--- a/video/adaptation/video_stream_encoder_resource_manager.h
+++ b/video/adaptation/video_stream_encoder_resource_manager.h
@@ -32,6 +32,7 @@
 #include "api/video_codecs/video_codec.h"
 #include "api/video_codecs/video_encoder.h"
 #include "api/video_codecs/video_encoder_config.h"
+#include "api/webrtc_key_value_config.h"
 #include "call/adaptation/resource_adaptation_processor_interface.h"
 #include "call/adaptation/video_stream_adapter.h"
 #include "call/adaptation/video_stream_input_state_provider.h"
@@ -79,7 +80,8 @@
       Clock* clock,
       bool experiment_cpu_load_estimator,
       std::unique_ptr<OveruseFrameDetector> overuse_detector,
-      DegradationPreferenceProvider* degradation_preference_provider);
+      DegradationPreferenceProvider* degradation_preference_provider,
+      const WebRtcKeyValueConfig& field_trials);
   ~VideoStreamEncoderResourceManager() override;
 
   void Initialize(rtc::TaskQueue* encoder_queue);
diff --git a/video/video_send_stream.cc b/video/video_send_stream.cc
index e78211b..8ab33de 100644
--- a/video/video_send_stream.cc
+++ b/video/video_send_stream.cc
@@ -114,7 +114,8 @@
     SendStatisticsProxy* stats_proxy,
     const VideoStreamEncoderSettings& encoder_settings,
     VideoStreamEncoder::BitrateAllocationCallbackType
-        bitrate_allocation_callback_type) {
+        bitrate_allocation_callback_type,
+    const WebRtcKeyValueConfig& field_trials) {
   std::unique_ptr<TaskQueueBase, TaskQueueDeleter> encoder_queue =
       task_queue_factory->CreateTaskQueue("EncoderQueue",
                                           TaskQueueFactory::Priority::NORMAL);
@@ -123,7 +124,7 @@
       clock, num_cpu_cores, stats_proxy, encoder_settings,
       std::make_unique<OveruseFrameDetector>(stats_proxy),
       FrameCadenceAdapterInterface::Create(clock, encoder_queue_ptr),
-      std::move(encoder_queue), bitrate_allocation_callback_type);
+      std::move(encoder_queue), bitrate_allocation_callback_type, field_trials);
 }
 
 }  // namespace
@@ -144,7 +145,8 @@
     VideoEncoderConfig encoder_config,
     const std::map<uint32_t, RtpState>& suspended_ssrcs,
     const std::map<uint32_t, RtpPayloadState>& suspended_payload_states,
-    std::unique_ptr<FecController> fec_controller)
+    std::unique_ptr<FecController> fec_controller,
+    const WebRtcKeyValueConfig& field_trials)
     : rtp_transport_queue_(transport->GetWorkerQueue()),
       transport_(transport),
       stats_proxy_(clock, config, encoder_config.content_type),
@@ -156,7 +158,8 @@
                                    task_queue_factory,
                                    &stats_proxy_,
                                    config_.encoder_settings,
-                                   GetBitrateAllocationCallbackType(config_))),
+                                   GetBitrateAllocationCallbackType(config_),
+                                   field_trials)),
       encoder_feedback_(
           clock,
           config_.rtp.ssrcs,
diff --git a/video/video_send_stream.h b/video/video_send_stream.h
index d1afefa..048de3d 100644
--- a/video/video_send_stream.h
+++ b/video/video_send_stream.h
@@ -18,6 +18,7 @@
 #include "api/fec_controller.h"
 #include "api/sequence_checker.h"
 #include "api/video/video_stream_encoder_interface.h"
+#include "api/webrtc_key_value_config.h"
 #include "call/bitrate_allocator.h"
 #include "call/video_receive_stream.h"
 #include "call/video_send_stream.h"
@@ -68,7 +69,8 @@
       VideoEncoderConfig encoder_config,
       const std::map<uint32_t, RtpState>& suspended_ssrcs,
       const std::map<uint32_t, RtpPayloadState>& suspended_payload_states,
-      std::unique_ptr<FecController> fec_controller);
+      std::unique_ptr<FecController> fec_controller,
+      const WebRtcKeyValueConfig& field_trials);
 
   ~VideoSendStream() override;
 
diff --git a/video/video_stream_encoder.cc b/video/video_stream_encoder.cc
index 147e011..4c59759 100644
--- a/video/video_stream_encoder.cc
+++ b/video/video_stream_encoder.cc
@@ -30,6 +30,7 @@
 #include "api/video/video_layers_allocation.h"
 #include "api/video_codecs/sdp_video_format.h"
 #include "api/video_codecs/video_encoder.h"
+#include "api/webrtc_key_value_config.h"
 #include "call/adaptation/resource_adaptation_processor.h"
 #include "call/adaptation/video_stream_adapter.h"
 #include "modules/video_coding/include/video_codec_initializer.h"
@@ -597,7 +598,8 @@
     std::unique_ptr<FrameCadenceAdapterInterface> frame_cadence_adapter,
     std::unique_ptr<webrtc::TaskQueueBase, webrtc::TaskQueueDeleter>
         encoder_queue,
-    BitrateAllocationCallbackType allocation_cb_type)
+    BitrateAllocationCallbackType allocation_cb_type,
+    const WebRtcKeyValueConfig& field_trials)
     : worker_queue_(TaskQueueBase::Current()),
       number_of_cores_(number_of_cores),
       sink_(nullptr),
@@ -645,7 +647,8 @@
       input_state_provider_(encoder_stats_observer),
       video_stream_adapter_(
           std::make_unique<VideoStreamAdapter>(&input_state_provider_,
-                                               encoder_stats_observer)),
+                                               encoder_stats_observer,
+                                               field_trials)),
       degradation_preference_manager_(
           std::make_unique<DegradationPreferenceManager>(
               video_stream_adapter_.get())),
@@ -655,7 +658,8 @@
                                clock_,
                                settings_.experiment_cpu_load_estimator,
                                std::move(overuse_detector),
-                               degradation_preference_manager_.get()),
+                               degradation_preference_manager_.get(),
+                               field_trials),
       video_source_sink_controller_(/*sink=*/frame_cadence_adapter_.get(),
                                     /*source=*/nullptr),
       default_limits_allowed_(
diff --git a/video/video_stream_encoder.h b/video/video_stream_encoder.h
index c667f04..e89ba4a 100644
--- a/video/video_stream_encoder.h
+++ b/video/video_stream_encoder.h
@@ -28,6 +28,7 @@
 #include "api/video/video_stream_encoder_settings.h"
 #include "api/video_codecs/video_codec.h"
 #include "api/video_codecs/video_encoder.h"
+#include "api/webrtc_key_value_config.h"
 #include "call/adaptation/adaptation_constraint.h"
 #include "call/adaptation/resource_adaptation_processor.h"
 #include "call/adaptation/resource_adaptation_processor_interface.h"
@@ -79,7 +80,8 @@
       std::unique_ptr<FrameCadenceAdapterInterface> frame_cadence_adapter,
       std::unique_ptr<webrtc::TaskQueueBase, webrtc::TaskQueueDeleter>
           encoder_queue,
-      BitrateAllocationCallbackType allocation_cb_type);
+      BitrateAllocationCallbackType allocation_cb_type,
+      const WebRtcKeyValueConfig& field_trials);
   ~VideoStreamEncoder() override;
 
   VideoStreamEncoder(const VideoStreamEncoder&) = delete;
diff --git a/video/video_stream_encoder_unittest.cc b/video/video_stream_encoder_unittest.cc
index aea1988..03ee684 100644
--- a/video/video_stream_encoder_unittest.cc
+++ b/video/video_stream_encoder_unittest.cc
@@ -55,15 +55,14 @@
 #include "rtc_base/logging.h"
 #include "rtc_base/ref_counted_object.h"
 #include "rtc_base/synchronization/mutex.h"
-#include "system_wrappers/include/field_trial.h"
 #include "system_wrappers/include/metrics.h"
 #include "test/encoder_settings.h"
 #include "test/fake_encoder.h"
-#include "test/field_trial.h"
 #include "test/frame_forwarder.h"
 #include "test/gmock.h"
 #include "test/gtest.h"
 #include "test/mappable_native_buffer.h"
+#include "test/scoped_key_value_config.h"
 #include "test/time_controller/simulated_time_controller.h"
 #include "test/video_encoder_proxy_factory.h"
 #include "video/frame_cadence_adapter.h"
@@ -375,7 +374,8 @@
       SendStatisticsProxy* stats_proxy,
       const VideoStreamEncoderSettings& settings,
       VideoStreamEncoder::BitrateAllocationCallbackType
-          allocation_callback_type)
+          allocation_callback_type,
+      const WebRtcKeyValueConfig& field_trials)
       : VideoStreamEncoder(time_controller->GetClock(),
                            1 /* number_of_cores */,
                            stats_proxy,
@@ -385,7 +385,8 @@
                                    new CpuOveruseDetectorProxy(stats_proxy)),
                            std::move(cadence_adapter),
                            std::move(encoder_queue),
-                           allocation_callback_type),
+                           allocation_callback_type,
+                           field_trials),
         time_controller_(time_controller),
         fake_cpu_resource_(FakeResource::Create("FakeResource[CPU]")),
         fake_quality_resource_(FakeResource::Create("FakeResource[QP]")),
@@ -678,7 +679,8 @@
 
   std::unique_ptr<AdaptedVideoStreamEncoder> CreateWithEncoderQueue(
       std::unique_ptr<FrameCadenceAdapterInterface> zero_hertz_adapter,
-      std::unique_ptr<TaskQueueBase, TaskQueueDeleter> encoder_queue) {
+      std::unique_ptr<TaskQueueBase, TaskQueueDeleter> encoder_queue,
+      const WebRtcKeyValueConfig* field_trials = nullptr) {
     auto result = std::make_unique<AdaptedVideoStreamEncoder>(
         time_controller_.GetClock(),
         /*number_of_cores=*/1,
@@ -686,7 +688,8 @@
         std::make_unique<CpuOveruseDetectorProxy>(/*stats_proxy=*/nullptr),
         std::move(zero_hertz_adapter), std::move(encoder_queue),
         VideoStreamEncoder::BitrateAllocationCallbackType::
-            kVideoBitrateAllocation);
+            kVideoBitrateAllocation,
+        field_trials ? *field_trials : field_trials_);
     result->SetSink(&sink_, /*rotation_applied=*/false);
     return result;
   }
@@ -730,6 +733,7 @@
     }
   };
 
+  test::ScopedKeyValueConfig field_trials_;
   GlobalSimulatedTimeController time_controller_{Timestamp::Millis(0)};
   std::unique_ptr<TaskQueueFactory> task_queue_factory_{
       time_controller_.CreateTaskQueueFactory()};
@@ -852,7 +856,7 @@
     video_stream_encoder_ = std::make_unique<VideoStreamEncoderUnderTest>(
         &time_controller_, std::move(cadence_adapter), std::move(encoder_queue),
         stats_proxy_.get(), video_send_config_.encoder_settings,
-        allocation_callback_type);
+        allocation_callback_type, field_trials_);
     video_stream_encoder_->SetSink(&sink_, /*rotation_applied=*/false);
     video_stream_encoder_->SetSource(
         &video_source_, webrtc::DegradationPreference::MAINTAIN_FRAMERATE);
@@ -1568,6 +1572,7 @@
     return time_controller_.GetTaskQueueFactory();
   }
 
+  test::ScopedKeyValueConfig field_trials_;
   GlobalSimulatedTimeController time_controller_{Timestamp::Micros(1234)};
   VideoSendStream::Config video_send_config_;
   VideoEncoderConfig video_encoder_config_;
@@ -4119,7 +4124,8 @@
 };
 
 TEST_F(BalancedDegradationTest, AdaptDownTwiceIfMinFpsDiffLtThreshold) {
-  test::ScopedFieldTrials field_trials(
+  test::ScopedKeyValueConfig field_trials(
+      field_trials_,
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:57600|129600|230400,fps:7|10|24,fps_diff:1|1|1/");
   SetupTest();
@@ -4143,7 +4149,8 @@
 }
 
 TEST_F(BalancedDegradationTest, AdaptDownOnceIfFpsDiffGeThreshold) {
-  test::ScopedFieldTrials field_trials(
+  test::ScopedKeyValueConfig field_trials(
+      field_trials_,
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:57600|129600|230400,fps:7|10|24,fps_diff:1|1|1/");
   SetupTest();
@@ -4166,7 +4173,8 @@
 }
 
 TEST_F(BalancedDegradationTest, AdaptDownUsesCodecSpecificFps) {
-  test::ScopedFieldTrials field_trials(
+  test::ScopedKeyValueConfig field_trials(
+      field_trials_,
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:57600|129600|230400,fps:7|10|24,vp8_fps:8|11|22/");
   SetupTest();
@@ -4184,7 +4192,8 @@
 }
 
 TEST_F(BalancedDegradationTest, NoAdaptUpIfBwEstimateIsLessThanMinBitrate) {
-  test::ScopedFieldTrials field_trials(
+  test::ScopedKeyValueConfig field_trials(
+      field_trials_,
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:57600|129600|230400,fps:7|10|14,kbps:0|0|425/");
   SetupTest();
@@ -4233,7 +4242,8 @@
 
 TEST_F(BalancedDegradationTest,
        InitialFrameDropAdaptsFpsAndResolutionInOneStep) {
-  test::ScopedFieldTrials field_trials(
+  test::ScopedKeyValueConfig field_trials(
+      field_trials_,
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:57600|129600|230400,fps:7|24|24/");
   SetupTest();
@@ -4264,7 +4274,8 @@
 
 TEST_F(BalancedDegradationTest,
        NoAdaptUpInResolutionIfBwEstimateIsLessThanMinBitrate) {
-  test::ScopedFieldTrials field_trials(
+  test::ScopedKeyValueConfig field_trials(
+      field_trials_,
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:57600|129600|230400,fps:7|10|14,kbps_res:0|0|435/");
   SetupTest();
@@ -4318,7 +4329,8 @@
 
 TEST_F(BalancedDegradationTest,
        NoAdaptUpInFpsAndResolutionIfBwEstimateIsLessThanMinBitrate) {
-  test::ScopedFieldTrials field_trials(
+  test::ScopedKeyValueConfig field_trials(
+      field_trials_,
       "WebRTC-Video-BalancedDegradationSettings/"
       "pixels:57600|129600|230400,fps:7|10|14,kbps:0|0|425,kbps_res:0|0|435/");
   SetupTest();
@@ -5199,7 +5211,8 @@
 }
 
 TEST_F(VideoStreamEncoderTest, VerifyBitrateAllocationForTwoStreams) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
+      field_trials_,
       "WebRTC-Video-QualityScalerSettings/"
       "initial_bitrate_interval_ms:1000,initial_bitrate_factor:0.2/");
   // Reset encoder for field trials to take effect.
@@ -5502,7 +5515,8 @@
 }
 
 TEST_F(VideoStreamEncoderTest, InitialFrameDropActivatesWhenBweDrops) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
+      field_trials_,
       "WebRTC-Video-QualityScalerSettings/"
       "initial_bitrate_interval_ms:1000,initial_bitrate_factor:0.2/");
   // Reset encoder for field trials to take effect.
@@ -5542,7 +5556,8 @@
 
 TEST_F(VideoStreamEncoderTest,
        InitialFrameDropNotReactivatedWhenBweDropsWhenScalingDisabled) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
+      field_trials_,
       "WebRTC-Video-QualityScalerSettings/"
       "initial_bitrate_interval_ms:1000,initial_bitrate_factor:0.2/");
   fake_encoder_.SetQualityScaling(false);
@@ -5833,8 +5848,8 @@
 }
 
 TEST_F(VideoStreamEncoderTest, DefaultMaxAndMinBitratesNotUsedIfDisabled) {
-  webrtc::test::ScopedFieldTrials field_trials(
-      "WebRTC-DefaultBitrateLimitsKillSwitch/Enabled/");
+  webrtc::test::ScopedKeyValueConfig field_trials(
+      field_trials_, "WebRTC-DefaultBitrateLimitsKillSwitch/Enabled/");
   VideoEncoderConfig video_encoder_config;
   test::FillEncoderConfiguration(PayloadStringToCodecType("VP9"), 1,
                                  &video_encoder_config);
@@ -6088,7 +6103,8 @@
 }
 
 TEST_F(VideoStreamEncoderTest, RampsUpInQualityWhenBwIsHigh) {
-  webrtc::test::ScopedFieldTrials field_trials(
+  webrtc::test::ScopedKeyValueConfig field_trials(
+      field_trials_,
       "WebRTC-Video-QualityRampupSettings/"
       "min_pixels:921600,min_duration_ms:2000/");
 
@@ -6164,8 +6180,8 @@
 
 TEST_F(VideoStreamEncoderTest,
        QualityScalerAdaptationsRemovedWhenQualityScalingDisabled) {
-  webrtc::test::ScopedFieldTrials field_trials(
-      "WebRTC-Video-QualityScaling/Disabled/");
+  webrtc::test::ScopedKeyValueConfig field_trials(
+      field_trials_, "WebRTC-Video-QualityScaling/Disabled/");
   AdaptingFrameForwarder source(&time_controller_);
   source.set_adaptation_enabled(true);
   video_stream_encoder_->SetSource(&source,
@@ -7743,7 +7759,8 @@
 }
 
 TEST_F(VideoStreamEncoderTest, AutomaticAnimationDetection) {
-  test::ScopedFieldTrials field_trials(
+  test::ScopedKeyValueConfig field_trials(
+      field_trials_,
       "WebRTC-AutomaticAnimationDetectionScreenshare/"
       "enabled:true,min_fps:20,min_duration_ms:1000,min_area_ratio:0.8/");
   const int kFramerateFps = 30;
@@ -8058,8 +8075,8 @@
 }
 
 TEST_F(VideoStreamEncoderTest, QpAbsentParsingDisabled_QpAbsent) {
-  webrtc::test::ScopedFieldTrials field_trials(
-      "WebRTC-QpParsingKillSwitch/Enabled/");
+  webrtc::test::ScopedKeyValueConfig field_trials(
+      field_trials_, "WebRTC-QpParsingKillSwitch/Enabled/");
 
   ResetEncoder("VP8", 1, 1, 1, false);
 
@@ -8904,6 +8921,8 @@
   std::unique_ptr<webrtc::TaskQueueBase, webrtc::TaskQueueDeleter>
       encoder_queue(new SuperLazyTaskQueue());
 
+  test::ScopedKeyValueConfig field_trials;
+
   // Construct a VideoStreamEncoder instance and let it go out of scope without
   // doing anything else (including calling Stop()). This should be fine since
   // the posted init task will simply be deleted.
@@ -8912,7 +8931,8 @@
       std::make_unique<CpuOveruseDetectorProxy>(stats_proxy.get()),
       std::move(adapter), std::move(encoder_queue),
       VideoStreamEncoder::BitrateAllocationCallbackType::
-          kVideoBitrateAllocation);
+          kVideoBitrateAllocation,
+      field_trials);
 }
 
 TEST(VideoStreamEncoderFrameCadenceTest, ActivatesFrameCadenceOnContentType) {
@@ -9177,14 +9197,15 @@
           "EncoderQueue", TaskQueueFactory::Priority::NORMAL);
 
   // Enables zero-hertz mode.
-  test::ScopedFieldTrials field_trials("WebRTC-ZeroHertzScreenshare/Enabled/");
+  test::ScopedKeyValueConfig field_trials(
+      "WebRTC-ZeroHertzScreenshare/Enabled/");
   auto adapter = FrameCadenceAdapterInterface::Create(
       factory.GetTimeController()->GetClock(), encoder_queue.get());
   FrameCadenceAdapterInterface* adapter_ptr = adapter.get();
 
   MockVideoSourceInterface mock_source;
   auto video_stream_encoder = factory.CreateWithEncoderQueue(
-      std::move(adapter), std::move(encoder_queue));
+      std::move(adapter), std::move(encoder_queue), &field_trials);
 
   video_stream_encoder->SetSource(
       &mock_source, webrtc::DegradationPreference::MAINTAIN_FRAMERATE);