Add field trial for vp8 cpu speed configuration for arm.

Bug: none
Change-Id: I90c2475a229a1f10016e2ad84029e19b5a4f9966
Reviewed-on: https://webrtc-review.googlesource.com/c/107340
Commit-Queue: Åsa Persson <asapersson@webrtc.org>
Reviewed-by: Stefan Holmer <stefan@webrtc.org>
Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25484}
diff --git a/modules/video_coding/BUILD.gn b/modules/video_coding/BUILD.gn
index 0e4805d..ff1e202 100644
--- a/modules/video_coding/BUILD.gn
+++ b/modules/video_coding/BUILD.gn
@@ -425,6 +425,7 @@
     "../../rtc_base:checks",
     "../../rtc_base:rtc_base_approved",
     "../../rtc_base:rtc_numerics",
+    "../../rtc_base/experiments:cpu_speed_experiment",
     "../../system_wrappers",
     "../../system_wrappers:field_trial",
     "../../system_wrappers:metrics",
diff --git a/modules/video_coding/codecs/vp8/libvpx_vp8_encoder.cc b/modules/video_coding/codecs/vp8/libvpx_vp8_encoder.cc
index b199f65..e4be823 100644
--- a/modules/video_coding/codecs/vp8/libvpx_vp8_encoder.cc
+++ b/modules/video_coding/codecs/vp8/libvpx_vp8_encoder.cc
@@ -142,6 +142,7 @@
 
 LibvpxVp8Encoder::LibvpxVp8Encoder(std::unique_ptr<LibvpxInterface> interface)
     : libvpx_(std::move(interface)),
+      experimental_cpu_speed_config_arm_(CpuSpeedExperiment::GetConfigs()),
       encoded_complete_callback_(nullptr),
       inited_(false),
       timestamp_(0),
@@ -432,10 +433,10 @@
   }
   cpu_speed_default_ = cpu_speed_[0];
   // Set encoding complexity (cpu_speed) based on resolution and/or platform.
-  cpu_speed_[0] = SetCpuSpeed(inst->width, inst->height);
+  cpu_speed_[0] = GetCpuSpeed(inst->width, inst->height);
   for (int i = 1; i < number_of_streams; ++i) {
     cpu_speed_[i] =
-        SetCpuSpeed(inst->simulcastStream[number_of_streams - 1 - i].width,
+        GetCpuSpeed(inst->simulcastStream[number_of_streams - 1 - i].width,
                     inst->simulcastStream[number_of_streams - 1 - i].height);
   }
   configurations_[0].g_w = inst->width;
@@ -507,7 +508,7 @@
   return InitAndSetControlSettings();
 }
 
-int LibvpxVp8Encoder::SetCpuSpeed(int width, int height) {
+int LibvpxVp8Encoder::GetCpuSpeed(int width, int height) {
 #if defined(WEBRTC_ARCH_ARM) || defined(WEBRTC_ARCH_ARM64) || \
     defined(WEBRTC_ANDROID)
   // On mobile platform, use a lower speed setting for lower resolutions for
@@ -516,6 +517,11 @@
   if (number_of_cores_ <= 3)
     return -12;
 
+  if (experimental_cpu_speed_config_arm_) {
+    return CpuSpeedExperiment::GetValue(width * height,
+                                        *experimental_cpu_speed_config_arm_);
+  }
+
   if (width * height <= 352 * 288)
     return -8;
   else if (width * height <= 640 * 480)
diff --git a/modules/video_coding/codecs/vp8/libvpx_vp8_encoder.h b/modules/video_coding/codecs/vp8/libvpx_vp8_encoder.h
index 7fffbab..362a079 100644
--- a/modules/video_coding/codecs/vp8/libvpx_vp8_encoder.h
+++ b/modules/video_coding/codecs/vp8/libvpx_vp8_encoder.h
@@ -22,6 +22,7 @@
 #include "modules/video_coding/codecs/vp8/include/vp8.h"
 #include "modules/video_coding/codecs/vp8/libvpx_interface.h"
 #include "modules/video_coding/include/video_codec_interface.h"
+#include "rtc_base/experiments/cpu_speed_experiment.h"
 
 #include "vpx/vp8cx.h"
 #include "vpx/vpx_encoder.h"
@@ -61,8 +62,8 @@
  private:
   void SetupTemporalLayers(const VideoCodec& codec);
 
-  // Set the cpu_speed setting for encoder based on resolution and/or platform.
-  int SetCpuSpeed(int width, int height);
+  // Get the cpu_speed setting for encoder based on resolution and/or platform.
+  int GetCpuSpeed(int width, int height);
 
   // Determine number of encoder threads to use.
   int NumberOfThreads(int width, int height, int number_of_cores);
@@ -87,6 +88,9 @@
 
   const std::unique_ptr<LibvpxInterface> libvpx_;
 
+  const absl::optional<std::vector<CpuSpeedExperiment::Config>>
+      experimental_cpu_speed_config_arm_;
+
   EncodedImageCallback* encoded_complete_callback_;
   VideoCodec codec_;
   bool inited_;