Changed the delay estimator to be built using C++

BUG=webrtc:5724
NOPRESUBMIT=true

Review URL: https://codereview.webrtc.org/1878613002

Cr-Commit-Position: refs/heads/master@{#12336}
diff --git a/webrtc/modules/audio_processing/BUILD.gn b/webrtc/modules/audio_processing/BUILD.gn
index 1060ec8..006d3a7 100644
--- a/webrtc/modules/audio_processing/BUILD.gn
+++ b/webrtc/modules/audio_processing/BUILD.gn
@@ -110,10 +110,10 @@
     "typing_detection.h",
     "utility/block_mean_calculator.cc",
     "utility/block_mean_calculator.h",
-    "utility/delay_estimator.c",
+    "utility/delay_estimator.cc",
     "utility/delay_estimator.h",
     "utility/delay_estimator_internal.h",
-    "utility/delay_estimator_wrapper.c",
+    "utility/delay_estimator_wrapper.cc",
     "utility/delay_estimator_wrapper.h",
     "vad/common.h",
     "vad/gmm.cc",
diff --git a/webrtc/modules/audio_processing/aec/aec_core.cc b/webrtc/modules/audio_processing/aec/aec_core.cc
index c4379c6..27a897a 100644
--- a/webrtc/modules/audio_processing/aec/aec_core.cc
+++ b/webrtc/modules/audio_processing/aec/aec_core.cc
@@ -35,9 +35,7 @@
 #include "webrtc/modules/audio_processing/aec/aec_rdft.h"
 }
 #include "webrtc/modules/audio_processing/logging/aec_logging.h"
-extern "C" {
 #include "webrtc/modules/audio_processing/utility/delay_estimator_wrapper.h"
-}
 #include "webrtc/system_wrappers/include/cpu_features_wrapper.h"
 #include "webrtc/typedefs.h"
 
diff --git a/webrtc/modules/audio_processing/aecm/aecm_core.cc b/webrtc/modules/audio_processing/aecm/aecm_core.cc
index 8a5524e..efaa7f0 100644
--- a/webrtc/modules/audio_processing/aecm/aecm_core.cc
+++ b/webrtc/modules/audio_processing/aecm/aecm_core.cc
@@ -19,10 +19,11 @@
 #include "webrtc/common_audio/signal_processing/include/real_fft.h"
 }
 #include "webrtc/modules/audio_processing/aecm/echo_control_mobile.h"
-extern "C" {
 #include "webrtc/modules/audio_processing/utility/delay_estimator_wrapper.h"
+extern "C" {
 #include "webrtc/system_wrappers/include/cpu_features_wrapper.h"
 }
+
 #include "webrtc/typedefs.h"
 
 #ifdef AEC_DEBUG
diff --git a/webrtc/modules/audio_processing/aecm/aecm_core_c.cc b/webrtc/modules/audio_processing/aecm/aecm_core_c.cc
index 3ee053b..57f859f 100644
--- a/webrtc/modules/audio_processing/aecm/aecm_core_c.cc
+++ b/webrtc/modules/audio_processing/aecm/aecm_core_c.cc
@@ -19,8 +19,8 @@
 #include "webrtc/common_audio/signal_processing/include/real_fft.h"
 }
 #include "webrtc/modules/audio_processing/aecm/echo_control_mobile.h"
-extern "C" {
 #include "webrtc/modules/audio_processing/utility/delay_estimator_wrapper.h"
+extern "C" {
 #include "webrtc/system_wrappers/include/cpu_features_wrapper.h"
 }
 #include "webrtc/typedefs.h"
diff --git a/webrtc/modules/audio_processing/aecm/aecm_core_mips.cc b/webrtc/modules/audio_processing/aecm/aecm_core_mips.cc
index bca32fe..e625a46 100644
--- a/webrtc/modules/audio_processing/aecm/aecm_core_mips.cc
+++ b/webrtc/modules/audio_processing/aecm/aecm_core_mips.cc
@@ -13,9 +13,7 @@
 #include <assert.h>
 
 #include "webrtc/modules/audio_processing/aecm/echo_control_mobile.h"
-extern "C" {
 #include "webrtc/modules/audio_processing/utility/delay_estimator_wrapper.h"
-}
 
 static const ALIGN8_BEG int16_t WebRtcAecm_kSqrtHanning[] ALIGN8_END = {
   0, 399, 798, 1196, 1594, 1990, 2386, 2780, 3172,
diff --git a/webrtc/modules/audio_processing/audio_processing.gypi b/webrtc/modules/audio_processing/audio_processing.gypi
index 2b47f7e..45b3aa3 100644
--- a/webrtc/modules/audio_processing/audio_processing.gypi
+++ b/webrtc/modules/audio_processing/audio_processing.gypi
@@ -120,10 +120,10 @@
         'typing_detection.h',
         'utility/block_mean_calculator.cc',
         'utility/block_mean_calculator.h',
-        'utility/delay_estimator.c',
+        'utility/delay_estimator.cc',
         'utility/delay_estimator.h',
         'utility/delay_estimator_internal.h',
-        'utility/delay_estimator_wrapper.c',
+        'utility/delay_estimator_wrapper.cc',
         'utility/delay_estimator_wrapper.h',
         'vad/common.h',
         'vad/gmm.cc',
diff --git a/webrtc/modules/audio_processing/utility/delay_estimator.c b/webrtc/modules/audio_processing/utility/delay_estimator.cc
similarity index 97%
rename from webrtc/modules/audio_processing/utility/delay_estimator.c
rename to webrtc/modules/audio_processing/utility/delay_estimator.cc
index f9f3dc2..15a6747 100644
--- a/webrtc/modules/audio_processing/utility/delay_estimator.c
+++ b/webrtc/modules/audio_processing/utility/delay_estimator.cc
@@ -276,7 +276,8 @@
 
   if (history_size > 1) {
     // Sanity conditions fulfilled.
-    self = malloc(sizeof(BinaryDelayEstimatorFarend));
+    self = static_cast<BinaryDelayEstimatorFarend*>(
+        malloc(sizeof(BinaryDelayEstimatorFarend)));
   }
   if (self == NULL) {
     return NULL;
@@ -296,11 +297,12 @@
                                       int history_size) {
   assert(self != NULL);
   // (Re-)Allocate memory for history buffers.
-  self->binary_far_history =
+  self->binary_far_history = static_cast<uint32_t*>(
       realloc(self->binary_far_history,
-              history_size * sizeof(*self->binary_far_history));
-  self->far_bit_counts = realloc(self->far_bit_counts,
-                                 history_size * sizeof(*self->far_bit_counts));
+              history_size * sizeof(*self->binary_far_history)));
+  self->far_bit_counts = static_cast<int*>(
+      realloc(self->far_bit_counts,
+              history_size * sizeof(*self->far_bit_counts)));
   if ((self->binary_far_history == NULL) || (self->far_bit_counts == NULL)) {
     history_size = 0;
   }
@@ -404,7 +406,8 @@
 
   if ((farend != NULL) && (max_lookahead >= 0)) {
     // Sanity conditions fulfilled.
-    self = malloc(sizeof(BinaryDelayEstimator));
+    self = static_cast<BinaryDelayEstimator*>(
+        malloc(sizeof(BinaryDelayEstimator)));
   }
   if (self == NULL) {
     return NULL;
@@ -422,8 +425,8 @@
   self->mean_bit_counts = NULL;
   self->bit_counts = NULL;
   self->histogram = NULL;
-  self->binary_near_history =
-      malloc((max_lookahead + 1) * sizeof(*self->binary_near_history));
+  self->binary_near_history = static_cast<uint32_t*>(
+      malloc((max_lookahead + 1) * sizeof(*self->binary_near_history)));
   if (self->binary_near_history == NULL ||
       WebRtc_AllocateHistoryBufferMemory(self, farend->history_size) == 0) {
     WebRtc_FreeBinaryDelayEstimator(self);
@@ -444,13 +447,13 @@
   // The extra array element in |mean_bit_counts| and |histogram| is a dummy
   // element only used while |last_delay| == -2, i.e., before we have a valid
   // estimate.
-  self->mean_bit_counts =
+  self->mean_bit_counts = static_cast<int32_t*>(
       realloc(self->mean_bit_counts,
-              (history_size + 1) * sizeof(*self->mean_bit_counts));
-  self->bit_counts =
-      realloc(self->bit_counts, history_size * sizeof(*self->bit_counts));
-  self->histogram =
-      realloc(self->histogram, (history_size + 1) * sizeof(*self->histogram));
+              (history_size + 1) * sizeof(*self->mean_bit_counts)));
+  self->bit_counts = static_cast<int32_t*>(
+      realloc(self->bit_counts, history_size * sizeof(*self->bit_counts)));
+  self->histogram = static_cast<float*>(
+      realloc(self->histogram, (history_size + 1) * sizeof(*self->histogram)));
 
   if ((self->mean_bit_counts == NULL) ||
       (self->bit_counts == NULL) ||
diff --git a/webrtc/modules/audio_processing/utility/delay_estimator_unittest.cc b/webrtc/modules/audio_processing/utility/delay_estimator_unittest.cc
index 4ebe0e6..3e46763 100644
--- a/webrtc/modules/audio_processing/utility/delay_estimator_unittest.cc
+++ b/webrtc/modules/audio_processing/utility/delay_estimator_unittest.cc
@@ -10,11 +10,9 @@
 
 #include "testing/gtest/include/gtest/gtest.h"
 
-extern "C" {
 #include "webrtc/modules/audio_processing/utility/delay_estimator.h"
 #include "webrtc/modules/audio_processing/utility/delay_estimator_internal.h"
 #include "webrtc/modules/audio_processing/utility/delay_estimator_wrapper.h"
-}
 #include "webrtc/typedefs.h"
 
 namespace {
diff --git a/webrtc/modules/audio_processing/utility/delay_estimator_wrapper.c b/webrtc/modules/audio_processing/utility/delay_estimator_wrapper.cc
similarity index 95%
rename from webrtc/modules/audio_processing/utility/delay_estimator_wrapper.c
rename to webrtc/modules/audio_processing/utility/delay_estimator_wrapper.cc
index b5448bc..75c7abe 100644
--- a/webrtc/modules/audio_processing/utility/delay_estimator_wrapper.c
+++ b/webrtc/modules/audio_processing/utility/delay_estimator_wrapper.cc
@@ -16,7 +16,6 @@
 
 #include "webrtc/modules/audio_processing/utility/delay_estimator.h"
 #include "webrtc/modules/audio_processing/utility/delay_estimator_internal.h"
-#include "webrtc/system_wrappers/include/compile_assert_c.h"
 
 // Only bit |kBandFirst| through bit |kBandLast| are processed and
 // |kBandFirst| - |kBandLast| must be < 32.
@@ -144,10 +143,11 @@
 
   // Check if the sub band used in the delay estimation is small enough to fit
   // the binary spectra in a uint32_t.
-  COMPILE_ASSERT(kBandLast - kBandFirst < 32);
+  static_assert(kBandLast - kBandFirst < 32, "");
 
   if (spectrum_size >= kBandLast) {
-    self = malloc(sizeof(DelayEstimatorFarend));
+    self = static_cast<DelayEstimatorFarend*>(
+        malloc(sizeof(DelayEstimatorFarend)));
   }
 
   if (self != NULL) {
@@ -158,7 +158,8 @@
     memory_fail |= (self->binary_farend == NULL);
 
     // Allocate memory for spectrum buffers.
-    self->mean_far_spectrum = malloc(spectrum_size * sizeof(SpectrumType));
+    self->mean_far_spectrum =
+        static_cast<SpectrumType*>(malloc(spectrum_size * sizeof(SpectrumType)));
     memory_fail |= (self->mean_far_spectrum == NULL);
 
     self->spectrum_size = spectrum_size;
@@ -275,7 +276,7 @@
   DelayEstimatorFarend* farend = (DelayEstimatorFarend*) farend_handle;
 
   if (farend_handle != NULL) {
-    self = malloc(sizeof(DelayEstimator));
+    self = static_cast<DelayEstimator*>(malloc(sizeof(DelayEstimator)));
   }
 
   if (self != NULL) {
@@ -287,8 +288,8 @@
     memory_fail |= (self->binary_handle == NULL);
 
     // Allocate memory for spectrum buffers.
-    self->mean_near_spectrum = malloc(farend->spectrum_size *
-                                      sizeof(SpectrumType));
+    self->mean_near_spectrum = static_cast<SpectrumType*>(
+        malloc(farend->spectrum_size * sizeof(SpectrumType)));
     memory_fail |= (self->mean_near_spectrum == NULL);
 
     self->spectrum_size = farend->spectrum_size;
@@ -328,7 +329,7 @@
 }
 
 int WebRtc_set_history_size(void* handle, int history_size) {
-  DelayEstimator* self = handle;
+  DelayEstimator* self = static_cast<DelayEstimator*>(handle);
 
   if ((self == NULL) || (history_size <= 1)) {
     return -1;
@@ -337,7 +338,7 @@
 }
 
 int WebRtc_history_size(const void* handle) {
-  const DelayEstimator* self = handle;
+  const DelayEstimator* self = static_cast<const DelayEstimator*>(handle);
 
   if (self == NULL) {
     return -1;