From: csagan5 <32685696+csagan5@users.noreply.github.com>
Date: Sat, 20 Jan 2018 21:17:27 +0100
Subject: openH264: enable ARM/ARM64 optimizations

Enable the optimizations not only for ChromeOS but for all compatbile ARM/ARM64 architectures
Limit threads auto-detect only for iOS
---
 content/renderer/media_recorder/h264_encoder.cc |  6 ++--
 third_party/openh264/BUILD.gn                   | 39 +++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/content/renderer/media_recorder/h264_encoder.cc b/content/renderer/media_recorder/h264_encoder.cc
--- a/content/renderer/media_recorder/h264_encoder.cc
+++ b/content/renderer/media_recorder/h264_encoder.cc
@@ -149,11 +149,11 @@ void H264Encoder::ConfigureEncoderOnEncodingTaskRunner(const gfx::Size& size) {
     init_params.iRCMode = RC_OFF_MODE;
   }
 
-#if defined(OS_CHROMEOS)
-  init_params.iMultipleThreadIdc = 0;
-#else
+#if defined(OS_MACOSX)
   // Threading model: Set to 1 due to https://crbug.com/583348.
   init_params.iMultipleThreadIdc = 1;
+#else
+  init_params.iMultipleThreadIdc = 0;
 #endif
 
   // TODO(mcasas): consider reducing complexity if there are few CPUs available.
diff --git a/third_party/openh264/BUILD.gn b/third_party/openh264/BUILD.gn
--- a/third_party/openh264/BUILD.gn
+++ b/third_party/openh264/BUILD.gn
@@ -10,6 +10,7 @@ import("//third_party/yasm/yasm_assemble.gni")
 # Config shared by all openh264 targets.
 config("config") {
   cflags = []
+  defines = []
 
   if (is_chromeos && target_cpu == "arm") {
     # HAVE_NEON and __chromeos__ are needed for enabling NEON on ChromeOS
@@ -20,6 +21,20 @@ config("config") {
     ]
   }
 
+  # HAVE_NEON and __chromeos__ are needed for enabling NEON on ChromeOS
+  # devices.
+  if (is_chromeos && target_cpu == "arm") {
+    defines += [
+      "__chromeos__",
+    ]
+  }
+
+  if (target_cpu == "arm" || target_cpu == "arm64") {
+    defines += [
+      "HAVE_NEON",
+    ]
+  }
+
   # GCC and clang flags. MSVS (is_win && !is_clang) does not use cflags.
   if (!is_win || is_clang) {
     cflags += [
@@ -128,6 +143,14 @@ source_set("common") {
   }
   include_dirs = openh264_common_include_dirs
 
+  # enable ARM optimizations
+  if (target_cpu == "arm") {
+    sources += openh264_common_sources_asm_arm
+  }
+  if (target_cpu == "arm64") {
+    sources += openh264_common_sources_asm_arm64
+  }
+
   configs -= [ "//build/config/compiler:chromium_code" ]
   configs += [ "//build/config/compiler:no_chromium_code" ]
   configs += [ ":config" ]
@@ -154,6 +177,14 @@ source_set("processing") {
   }
   include_dirs = openh264_processing_include_dirs
 
+  # enable ARM optimizations
+  if (target_cpu == "arm") {
+    sources += openh264_common_sources_asm_arm
+  }
+  if (target_cpu == "arm64") {
+    sources += openh264_common_sources_asm_arm64
+  }
+
   configs -= [ "//build/config/compiler:chromium_code" ]
   configs += [ "//build/config/compiler:no_chromium_code" ]
   configs += [ ":config" ]
@@ -173,6 +204,14 @@ source_set("encoder") {
   }
   include_dirs = openh264_encoder_include_dirs
 
+  # enable ARM optimizations
+  if (target_cpu == "arm") {
+    sources += openh264_common_sources_asm_arm
+  }
+  if (target_cpu == "arm64") {
+    sources += openh264_common_sources_asm_arm64
+  }
+
   configs -= [ "//build/config/compiler:chromium_code" ]
   configs += [ "//build/config/compiler:no_chromium_code" ]
   configs += [ ":config" ]
-- 
2.7.4

