Reland: Fix circular dependency in BWE code.

Diff patch set 1 and 2 to see actual differences to the last
patch.

Bug: webrtc:6828
Change-Id: Ie0c85d41df47c2a2505bc71b20fdb3834bdeaf12
Reviewed-on: https://webrtc-review.googlesource.com/36920
Reviewed-by: Stefan Holmer <stefan@webrtc.org>
Commit-Queue: Patrik Höglund <phoglund@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21492}
diff --git a/modules/bitrate_controller/BUILD.gn b/modules/bitrate_controller/BUILD.gn
index f50341d..a791c33 100644
--- a/modules/bitrate_controller/BUILD.gn
+++ b/modules/bitrate_controller/BUILD.gn
@@ -9,11 +9,6 @@
 import("../../webrtc.gni")
 
 rtc_static_library("bitrate_controller") {
-  # TODO(mbonadei): Remove (bugs.webrtc.org/6828)
-  # Errors on cyclic dependency with:
-  # congestion_controller:congestion_controller if enabled.
-  check_includes = false
-
   sources = [
     "bitrate_controller_impl.cc",
     "bitrate_controller_impl.h",
@@ -37,9 +32,18 @@
   }
 
   deps = [
+    "..:module_api",
+    "../../logging:rtc_event_log_api",
+    "../../rtc_base:checks",
     "../../rtc_base:rtc_base_approved",
     "../../system_wrappers",
+    "../../system_wrappers:field_trial_api",
+    "../../system_wrappers:metrics_api",
+    "../congestion_controller:delay_based_bwe",
+    "../pacing",
+    "../remote_bitrate_estimator:remote_bitrate_estimator",
     "../rtp_rtcp",
+    "../rtp_rtcp:rtp_rtcp_format",
   ]
 }
 
diff --git a/modules/congestion_controller/BUILD.gn b/modules/congestion_controller/BUILD.gn
index d3e2b0e..e2c79a0 100644
--- a/modules/congestion_controller/BUILD.gn
+++ b/modules/congestion_controller/BUILD.gn
@@ -8,36 +8,27 @@
 
 import("../../webrtc.gni")
 
+config("bwe_test_logging") {
+  if (rtc_enable_bwe_test_logging) {
+    defines = [ "BWE_TEST_LOGGING_COMPILE_TIME_ENABLE=1" ]
+  } else {
+    defines = [ "BWE_TEST_LOGGING_COMPILE_TIME_ENABLE=0" ]
+  }
+}
+
 rtc_static_library("congestion_controller") {
+  configs += [ ":bwe_test_logging" ]
   sources = [
-    "acknowledged_bitrate_estimator.cc",
-    "acknowledged_bitrate_estimator.h",
-    "bitrate_estimator.cc",
-    "bitrate_estimator.h",
-    "delay_based_bwe.cc",
-    "delay_based_bwe.h",
     "include/receive_side_congestion_controller.h",
     "include/send_side_congestion_controller.h",
-    "median_slope_estimator.cc",
-    "median_slope_estimator.h",
-    "probe_bitrate_estimator.cc",
-    "probe_bitrate_estimator.h",
     "probe_controller.cc",
     "probe_controller.h",
     "receive_side_congestion_controller.cc",
     "send_side_congestion_controller.cc",
     "transport_feedback_adapter.cc",
     "transport_feedback_adapter.h",
-    "trendline_estimator.cc",
-    "trendline_estimator.h",
   ]
 
-  if (rtc_enable_bwe_test_logging) {
-    defines = [ "BWE_TEST_LOGGING_COMPILE_TIME_ENABLE=1" ]
-  } else {
-    defines = [ "BWE_TEST_LOGGING_COMPILE_TIME_ENABLE=0" ]
-  }
-
   # TODO(jschuh): Bug 1348: fix this warning.
   configs += [ "//build/config/compiler:no_size_t_to_int_warning" ]
 
@@ -47,16 +38,13 @@
   }
 
   deps = [
+    ":delay_based_bwe",
+    ":estimators",
     "..:module_api",
     "../..:webrtc_common",
-    "../../:typedefs",
-    "../../api:optional",
-    "../../logging:rtc_event_log_api",
     "../../rtc_base:checks",
     "../../rtc_base:rate_limiter",
     "../../rtc_base:rtc_base",
-    "../../rtc_base:rtc_base_approved",
-    "../../rtc_base:rtc_numerics",
     "../../system_wrappers",
     "../../system_wrappers:field_trial_api",
     "../../system_wrappers:metrics_api",
@@ -64,10 +52,69 @@
     "../pacing",
     "../remote_bitrate_estimator",
     "../rtp_rtcp:rtp_rtcp_format",
-    "../utility",
   ]
 }
 
+rtc_source_set("estimators") {
+  configs += [ ":bwe_test_logging" ]
+  sources = [
+    "acknowledged_bitrate_estimator.cc",
+    "acknowledged_bitrate_estimator.h",
+    "bitrate_estimator.cc",
+    "bitrate_estimator.h",
+    "median_slope_estimator.cc",
+    "median_slope_estimator.h",
+    "probe_bitrate_estimator.cc",
+    "probe_bitrate_estimator.h",
+    "trendline_estimator.cc",
+    "trendline_estimator.h",
+  ]
+
+  # TODO(jschuh): Bug 1348: fix this warning.
+  configs += [ "//build/config/compiler:no_size_t_to_int_warning" ]
+
+  if (!build_with_chromium && is_clang) {
+    # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
+    suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
+  }
+
+  deps = [
+    "../../api:optional",
+    "../../logging:rtc_event_log_api",
+    "../../rtc_base:checks",
+    "../../rtc_base:rtc_base_approved",
+    "../../rtc_base:rtc_numerics",
+    "../../system_wrappers:field_trial_api",
+    "../../system_wrappers:metrics_api",
+    "../remote_bitrate_estimator:remote_bitrate_estimator",
+    "../rtp_rtcp:rtp_rtcp_format",
+  ]
+}
+
+rtc_source_set("delay_based_bwe") {
+  configs += [ ":bwe_test_logging" ]
+  sources = [
+    "delay_based_bwe.cc",
+    "delay_based_bwe.h",
+  ]
+  deps = [
+    ":estimators",
+    "../../:typedefs",
+    "../../logging:rtc_event_log_api",
+    "../../rtc_base:checks",
+    "../../rtc_base:rtc_base_approved",
+    "../../system_wrappers:field_trial_api",
+    "../../system_wrappers:metrics_api",
+    "../pacing",
+    "../remote_bitrate_estimator",
+  ]
+
+  if (!build_with_chromium && is_clang) {
+    # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
+    suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
+  }
+}
+
 if (rtc_include_tests) {
   rtc_source_set("congestion_controller_unittests") {
     testonly = true
@@ -89,6 +136,8 @@
     ]
     deps = [
       ":congestion_controller",
+      ":delay_based_bwe",
+      ":estimators",
       ":mock_congestion_controller",
       "../../logging:mocks",
       "../../rtc_base:checks",
diff --git a/modules/remote_bitrate_estimator/BUILD.gn b/modules/remote_bitrate_estimator/BUILD.gn
index ef7ee11..89e74c4 100644
--- a/modules/remote_bitrate_estimator/BUILD.gn
+++ b/modules/remote_bitrate_estimator/BUILD.gn
@@ -155,6 +155,8 @@
       "../../voice_engine",
       "../bitrate_controller",
       "../congestion_controller",
+      "../congestion_controller:delay_based_bwe",
+      "../congestion_controller:estimators",
       "../pacing",
       "../rtp_rtcp",
       "../rtp_rtcp:rtp_rtcp_format",
diff --git a/rtc_tools/BUILD.gn b/rtc_tools/BUILD.gn
index 771d6d9..840d221 100644
--- a/rtc_tools/BUILD.gn
+++ b/rtc_tools/BUILD.gn
@@ -231,6 +231,7 @@
         "../modules/audio_coding:ana_debug_dump_proto",
         "../modules/audio_coding:audio_network_adaptor",
         "../modules/audio_coding:neteq_tools",
+        "../modules/congestion_controller:estimators",
         "../modules/rtp_rtcp:rtp_rtcp_format",
         "../rtc_base:checks",
         "../rtc_base:rtc_base_approved",