Split aec and aecm into separate build targets

This clarifies dependencies and makes it easier to customize builds
for different binaries.

Also adds BUILD files in aec/ and aecm/.

Moves unit tests to their own target, which subjects them to Chromium
Clang style checks.
The CL contains a fix for a thusly induced warning.

Bug: webrtc:9488
Change-Id: I77b680b42a4dccc5f025005e0890f60b4eaf2961
Reviewed-on: https://webrtc-review.googlesource.com/87304
Commit-Queue: Sam Zackrisson <saza@webrtc.org>
Reviewed-by: Alex Loiko <aleloi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23887}
diff --git a/modules/audio_processing/BUILD.gn b/modules/audio_processing/BUILD.gn
index b43a98b..4be7d8f 100644
--- a/modules/audio_processing/BUILD.gn
+++ b/modules/audio_processing/BUILD.gn
@@ -30,10 +30,6 @@
   visibility = [ "*" ]
   configs += [ ":apm_debug_dump" ]
   sources = [
-    "aec/aec_resampler.cc",
-    "aec/aec_resampler.h",
-    "aec/echo_cancellation.cc",
-    "aec/echo_cancellation.h",
     "audio_buffer.cc",
     "audio_buffer.h",
     "audio_processing_impl.cc",
@@ -99,7 +95,6 @@
 
   defines = []
   deps = [
-    ":aec_core",
     ":apm_logging",
     ":audio_frame_view",
     ":audio_generator_interface",
@@ -123,6 +118,9 @@
     "../../system_wrappers:cpu_features_api",
     "../../system_wrappers:field_trial_api",
     "../../system_wrappers:metrics_api",
+    "aec:aec",
+    "aec:aec_core",
+    "aecm:aecm_core",
     "agc",
     "agc:agc_legacy_c",
     "agc2:adaptive_digital",
@@ -317,81 +315,6 @@
   defines = []
 }
 
-rtc_source_set("aec_core") {
-  configs += [ ":apm_debug_dump" ]
-  sources = [
-    "aec/aec_common.h",
-    "aec/aec_core.cc",
-    "aec/aec_core.h",
-    "aec/aec_core_optimized_methods.h",
-    "aecm/aecm_core.cc",
-    "aecm/aecm_core.h",
-    "aecm/aecm_defines.h",
-    "aecm/echo_control_mobile.cc",
-    "aecm/echo_control_mobile.h",
-  ]
-  deps = [
-    ":apm_logging",
-    ":audio_processing_statistics",
-    "../..:typedefs",
-    "../..:webrtc_common",
-    "../../common_audio:common_audio",
-    "../../common_audio:common_audio_c",
-    "../../rtc_base:checks",
-    "../../rtc_base:rtc_base_approved",
-    "../../rtc_base:sanitizer",
-    "../../system_wrappers:cpu_features_api",
-    "../../system_wrappers:metrics_api",
-    "utility:block_mean_calculator",
-    "utility:legacy_delay_estimator",
-    "utility:ooura_fft",
-  ]
-  cflags = []
-  defines = []
-
-  if (current_cpu == "x86" || current_cpu == "x64") {
-    sources += [ "aec/aec_core_sse2.cc" ]
-    if (is_posix || is_fuchsia) {
-      cflags += [ "-msse2" ]
-    }
-  }
-
-  if (rtc_build_with_neon) {
-    sources += [
-      "aec/aec_core_neon.cc",
-      "aecm/aecm_core_neon.cc",
-    ]
-
-    if (current_cpu != "arm64") {
-      # Enable compilation for the NEON instruction set. This is needed
-      # since //build/config/arm.gni only enables NEON for iOS, not Android.
-      # This provides the same functionality as webrtc/build/arm_neon.gypi.
-      suppressed_configs += [ "//build/config/compiler:compiler_arm_fpu" ]
-      cflags += [ "-mfpu=neon" ]
-    }
-
-    # Disable LTO on NEON targets due to compiler bug.
-    # TODO(fdegans): Enable this. See crbug.com/408997.
-    if (rtc_use_lto) {
-      cflags -= [
-        "-flto",
-        "-ffat-lto-objects",
-      ]
-    }
-
-    deps += [ "../../common_audio" ]
-  }
-
-  if (current_cpu == "mipsel") {
-    sources += [ "aecm/aecm_core_mips.cc" ]
-    if (mips_float_abi == "hard") {
-      sources += [ "aec/aec_core_mips.cc" ]
-    }
-  } else {
-    sources += [ "aecm/aecm_core_c.cc" ]
-  }
-}
-
 if (rtc_include_tests) {
   rtc_source_set("mocks") {
     testonly = true
@@ -433,8 +356,6 @@
 
     configs += [ ":apm_debug_dump" ]
     sources = [
-      "aec/echo_cancellation_unittest.cc",
-      "aec/system_delay_unittest.cc",
       "audio_buffer_unittest.cc",
       "audio_frame_view_unittest.cc",
       "config_unittest.cc",
@@ -454,7 +375,6 @@
     ]
 
     deps = [
-      ":aec_core",
       ":analog_mic_simulation",
       ":apm_logging",
       ":audio_frame_view",
@@ -481,6 +401,8 @@
       "../../test:fileutils",
       "../../test:test_support",
       "../audio_coding:neteq_input_audio_tools",
+      "aec:aec_core",
+      "aec:aec_unittests",
       "aec_dump:mock_aec_dump_unittests",
       "agc:agc_unittests",
       "agc2:adaptive_digital_unittests",
diff --git a/modules/audio_processing/aec/BUILD.gn b/modules/audio_processing/aec/BUILD.gn
new file mode 100644
index 0000000..5a858f5
--- /dev/null
+++ b/modules/audio_processing/aec/BUILD.gn
@@ -0,0 +1,104 @@
+# Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
+#
+# Use of this source code is governed by a BSD-style license
+# that can be found in the LICENSE file in the root of the source
+# tree. An additional intellectual property rights grant can be found
+# in the file PATENTS.  All contributing project authors may
+# be found in the AUTHORS file in the root of the source tree.
+
+import("../../../webrtc.gni")
+
+rtc_source_set("aec") {
+  configs += [ "..:apm_debug_dump" ]
+  sources = [
+    "aec_resampler.cc",
+    "aec_resampler.h",
+    "echo_cancellation.cc",
+    "echo_cancellation.h",
+  ]
+  deps = [
+    ":aec_core",
+    "..:apm_logging",
+    "../../..:typedefs",
+    "../../../common_audio:common_audio_c",
+    "../../../rtc_base:checks",
+    "../../../rtc_base:rtc_base_approved",
+  ]
+}
+
+rtc_source_set("aec_core") {
+  configs += [ "..:apm_debug_dump" ]
+  sources = [
+    "aec_common.h",
+    "aec_core.cc",
+    "aec_core.h",
+    "aec_core_optimized_methods.h",
+  ]
+  deps = [
+    "..:apm_logging",
+    "../../..:typedefs",
+    "../../../common_audio:common_audio_c",
+    "../../../rtc_base:checks",
+    "../../../rtc_base:rtc_base_approved",
+    "../../../system_wrappers:cpu_features_api",
+    "../../../system_wrappers:metrics_api",
+    "../utility:block_mean_calculator",
+    "../utility:legacy_delay_estimator",
+    "../utility:ooura_fft",
+  ]
+  cflags = []
+
+  if (current_cpu == "x86" || current_cpu == "x64") {
+    sources += [ "aec_core_sse2.cc" ]
+    if (is_posix || is_fuchsia) {
+      cflags += [ "-msse2" ]
+    }
+  }
+
+  if (rtc_build_with_neon) {
+    sources += [ "aec_core_neon.cc" ]
+
+    if (current_cpu != "arm64") {
+      # Enable compilation for the NEON instruction set. This is needed
+      # since //build/config/arm.gni only enables NEON for iOS, not Android.
+      # This provides the same functionality as webrtc/build/arm_neon.gypi.
+      suppressed_configs += [ "//build/config/compiler:compiler_arm_fpu" ]
+      cflags += [ "-mfpu=neon" ]
+    }
+
+    # Disable LTO on NEON targets due to compiler bug.
+    # TODO(fdegans): Enable this. See crbug.com/408997.
+    if (rtc_use_lto) {
+      cflags -= [
+        "-flto",
+        "-ffat-lto-objects",
+      ]
+    }
+
+    deps += [ "../../../common_audio" ]
+  }
+
+  if (current_cpu == "mipsel" && mips_float_abi == "hard") {
+    sources += [ "aec_core_mips.cc" ]
+  }
+}
+
+if (rtc_include_tests) {
+  rtc_source_set("aec_unittests") {
+    testonly = true
+
+    sources = [
+      "echo_cancellation_unittest.cc",
+      "system_delay_unittest.cc",
+    ]
+    deps = [
+      ":aec",
+      ":aec_core",
+      "../../..:typedefs",
+      "../../../rtc_base:checks",
+      "../../../rtc_base:rtc_base_approved",
+      "../../../test:test_support",
+      "//testing/gtest",
+    ]
+  }
+}
diff --git a/modules/audio_processing/aec/system_delay_unittest.cc b/modules/audio_processing/aec/system_delay_unittest.cc
index e7e79fe..01119db 100644
--- a/modules/audio_processing/aec/system_delay_unittest.cc
+++ b/modules/audio_processing/aec/system_delay_unittest.cc
@@ -19,8 +19,8 @@
 class SystemDelayTest : public ::testing::Test {
  protected:
   SystemDelayTest();
-  virtual void SetUp();
-  virtual void TearDown();
+  void SetUp() override;
+  void TearDown() override;
 
   // Initialization of AEC handle with respect to |sample_rate_hz|. Since the
   // device sample rate is unimportant we set that value to 48000 Hz.
diff --git a/modules/audio_processing/aecm/BUILD.gn b/modules/audio_processing/aecm/BUILD.gn
new file mode 100644
index 0000000..54d839e
--- /dev/null
+++ b/modules/audio_processing/aecm/BUILD.gn
@@ -0,0 +1,56 @@
+# Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
+#
+# Use of this source code is governed by a BSD-style license
+# that can be found in the LICENSE file in the root of the source
+# tree. An additional intellectual property rights grant can be found
+# in the file PATENTS.  All contributing project authors may
+# be found in the AUTHORS file in the root of the source tree.
+
+import("../../../webrtc.gni")
+
+rtc_source_set("aecm_core") {
+  sources = [
+    "aecm_core.cc",
+    "aecm_core.h",
+    "aecm_defines.h",
+    "echo_control_mobile.cc",
+    "echo_control_mobile.h",
+  ]
+  deps = [
+    "../../..:typedefs",
+    "../../../common_audio:common_audio_c",
+    "../../../rtc_base:checks",
+    "../../../rtc_base:rtc_base_approved",
+    "../../../rtc_base:sanitizer",
+    "../../../system_wrappers:cpu_features_api",
+    "../utility:legacy_delay_estimator",
+  ]
+  cflags = []
+
+  if (rtc_build_with_neon) {
+    sources += [ "aecm_core_neon.cc" ]
+
+    if (current_cpu != "arm64") {
+      # Enable compilation for the NEON instruction set. This is needed
+      # since //build/config/arm.gni only enables NEON for iOS, not Android.
+      # This provides the same functionality as webrtc/build/arm_neon.gypi.
+      suppressed_configs += [ "//build/config/compiler:compiler_arm_fpu" ]
+      cflags += [ "-mfpu=neon" ]
+    }
+
+    # Disable LTO on NEON targets due to compiler bug.
+    # TODO(fdegans): Enable this. See crbug.com/408997.
+    if (rtc_use_lto) {
+      cflags -= [
+        "-flto",
+        "-ffat-lto-objects",
+      ]
+    }
+  }
+
+  if (current_cpu == "mipsel") {
+    sources += [ "aecm_core_mips.cc" ]
+  } else {
+    sources += [ "aecm_core_c.cc" ]
+  }
+}
diff --git a/modules/audio_processing/agc2/BUILD.gn b/modules/audio_processing/agc2/BUILD.gn
index 2a625b7..dcdc7fa 100644
--- a/modules/audio_processing/agc2/BUILD.gn
+++ b/modules/audio_processing/agc2/BUILD.gn
@@ -27,7 +27,6 @@
     ":gain_applier",
     ":noise_level_estimator",
     ":rnn_vad_with_level",
-    "..:aec_core",
     "..:apm_logging",
     "..:audio_frame_view",
     "../../..:typedefs",